开发者社区> 问答> 正文

视频点播客服端如何上传SDK?

视频点播客服端如何上传SDK?

展开
收起
保持可爱mmm 2020-03-30 13:39:46 733 0
1 条回答
写回答
取消 提交回答
  • 设置上传地址和凭证

    上传地址和凭证是跟每个文件一一对应的,所以建议在开始上传的回调里面再去用户应用服务器(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);
        }
        …… //其他回调
    });
    
    2020-03-30 13:42:01
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
互联网音视频点播业务云上实践 立即下载
一个跨平台的云服务SDK需要什么 立即下载
《VoD问题排查与实战手册》 立即下载

相关实验场景

更多