设置上传地址和凭证
上传地址和凭证是跟每个文件一一对应的,所以建议在开始上传的回调里面再去用户应用服务器(AppServer)进行获取并设置给上传实例。具体代码如下: iOS示例代码
// create VODUploadClient object
self.uploader = [VODUploadClient new];
// weakself
__weak typeof(self) weakSelf = self;
// setup callback
OnUploadFinishedListener FinishCallbackFunc = ^(UploadFileInfo* fileInfo, VodUploadResult* result){
NSLog(@"upload finished callback videoid:%@, imageurl:%@", result.videoId, result.imageUrl);
};
OnUploadFailedListener FailedCallbackFunc = ^(UploadFileInfo* fileInfo, NSString *code, NSString* message){
NSLog(@"upload failed callback code = %@, error message = %@", code, message);
};
OnUploadProgressListener ProgressCallbackFunc = ^(UploadFileInfo* fileInfo, long uploadedSize, long totalSize) {
NSLog(@"upload progress callback uploadedSize : %li, totalSize : %li", uploadedSize, totalSize);
};
OnUploadTokenExpiredListener TokenExpiredCallbackFunc = ^{
NSLog(@"upload token expired callback.");
// token过期,设置新的上传凭证,继续上传
};
OnUploadRertyListener RetryCallbackFunc = ^{
NSLog(@"upload retry begin callback.");
};
OnUploadRertyResumeListener RetryResumeCallbackFunc = ^{
NSLog(@"upload retry end callback.");
};
OnUploadStartedListener UploadStartedCallbackFunc = ^(UploadFileInfo* fileInfo) {
NSLog(@"upload upload started callback.");
// 设置上传地址 和 上传凭证
[weakSelf.uploader setUploadAuthAndAddress:fileInfo uploadAuth:`upload auth` uploadAddress:`upload address`];
};
VODUploadListener *listener = [[VODUploadListener alloc] init];
listener.finish = FinishCallbackFunc;
listener.failure = FailedCallbackFunc;
listener.progress = ProgressCallbackFunc;
listener.expire = TokenExpiredCallbackFunc;
listener.retry = RetryCallbackFunc;
listener.retryResume = RetryResumeCallbackFunc;
listener.started = UploadStartedCallbackFunc;
// init with upload address and upload auth
[self.uploader init:listener];
Android示例代码
VODUploadClient uploader = new VODUploadClientImpl(getApplicationContext());
VODUploadCallback callback = new VODUploadCallback() {
public void onUploadSucceed(UploadFileInfo info) {
//上传成功
}
public void onUploadFailed(UploadFileInfo info, String code, String message) {
//上传失败
}
public void onUploadProgress(UploadFileInfo info, long uploadedSize, long totalSize) {
//上传进度
}
public void onUploadTokenExpired() {
//上传凭证过期,需要调用刷新凭证接口。
}
public void onUploadRetry(String code, String message) {
//重试回调
}
public void onUploadRetryResume() {
}
public void onUploadStarted(UploadFileInfo uploadFileInfo) {
OSSLog.logError("onUploadStarted ------------- ");
//TODO:从业务服务器获取 “上传凭证和地址”
//设置:uploadAuth, uploadAddress
uploader.setUploadAuthAndAddress(uploadFileInfo, uploadAuth, uploadAddress);
}
};
uploader.init(callback);
H5 JS示例代码
var uploader = new AliyunUpload.Vod({
partSize: 1048576,//分片大小默认1M,不能小于100K
parallel: 5,//并行上传分片个数,默认5
retryCount: 3,//网络原因失败时,重新上传次数,默认为3
retryDuration: 2,//网络原因失败时,重新上传间隔时间,默认为2秒
'onUploadstarted': function (uploadInfo) {
uploader.setUploadAuthAndAddress(
uploadInfo,
uploadAuth,
uploadAddress,
videoId);
}
…… //其他回调
});
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。