文档中心 云点播 IOS 上传SDK

IOS 上传SDK

更新时间:2023-02-01 09:33:07

简介

云点播服务支持采用网宿云存储 IOS版 上传SDK,用于嵌入到IOS APP中,实现从移动手机端上传视频至云点播中。

SDK下载

下载地址
工程源码

快速集成

1)上传Token获取

详细见上传Token获取
!注意:Token必须使用云点播的接口获取,文件才能正常上传至云点播平台

2)初始化

初始化主要完成上传域名设置、分片上传并发数、响应超时时间、连接超时时间、重试次数。

通过配置文件统一设置上传,管理域名
/**
 创建一个用于发起请求的Client
 
 @param baseURL 当前所使用的域名(必填)
 @param timeout 超时时间
 @param concurrentCount 分片上传的并发数,范围为5~10。
 @param retryTimes 重试次数
 */
- (instancetype _Nonnull)initWithBaseURL:(NSURL * _Nullable)baseURL
                              andTimeout:(NSTimeInterval)timeout
                         concurrentCount:(NSUInteger)concurrentCount
                              retryTimes:(NSUInteger)retryTimes;

3)文件上传

普通上传
  WCSUploadObjectRequest *request = [[WCSUploadObjectRequest alloc] init];
  request.token = @"上传的token,由服务端提供";
  request.fileName = @"上传的文件名";
  request.key = @"上传到云端的文件名,不填云端则以fileName命名";
  request.fileData = fileData; // 要上传的文件
  request.uploadProgress = ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
    NSLog(@"%lld bytes sent, %lld total bytes sent, %lld total byte exptected", bytesSent, totalBytesSent, totalBytesExpectedToSend);
  };
  // 建议复用WCSClient
  WCSClient *client = [[WCSClient alloc] initWithBaseURL:[NSURL URLWithString:"upload.cloudv.haplat.net"] andTimeout:30];
  [[client uploadRequest:request] continueWithBlock:^id _Nullable(WCSTask<WCSUploadObjectResult *> * _Nonnull task) {
    if (task.error) {
      NSLog(@"The request failed. error: [%@]", task.error);
    } else {
      // 请求成功,以下为服务端返回的内容
      NSDictionary *responseResult = task.result.results;
    }
    return nil;
  }];

分片上传

移动端上传大文件需要耗费较长时间,一旦在传输过程中出现异常,文件内容需全部重传,影响用户体验,为避免这个问题,引进分片上传机制。
分片上传机制是将一个大文件切分成多个自定义大小的块,然后将这些块并行上传,如果某个块上传失败,客户端只需要重新上传这个块即可。
注意:每个块的最大大小不能超过100M;最小不能小于4M,否则将会采用默认4M去切分。

 WCSUploadObjectRequest *request = [[WCSUploadObjectRequest alloc] init];
  request.token = @"上传的token,由服务端提供";
  request.fileName = @"上传的文件名";
  request.key = @"上传到云端的文件名,不填云端则以fileName命名";
  request.fileData = fileData; // 要上传的文件
  request.blockSize = 8 * 1024 * 1024; // 块大小
  request.chunkSize = 64 * 1024; // 片大小
  request.uploadProgress = ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
    NSLog(@"%lld bytes sent, %lld total bytes sent, %lld total byte exptected", bytesSent, totalBytesSent, totalBytesExpectedToSend);
  };
  // 建议复用WCSClient
  WCSClient *client = [[WCSClient alloc] initWithBaseURL:nil andTimeout:30];
  [[client uploadRequest:request] continueWithBlock:^id _Nullable(WCSTask<WCSUploadObjectResult *> * _Nonnull task) {
    if (task.error) {
      NSLog(@"The request failed. error: [%@]", task.error);
    } else {
      // 请求成功,以下为服务端返回的内容
      NSDictionary *responseResult = task.result.results;
    }
    return nil;
  }];


本篇文档内容对您是否有帮助?
有帮助
我要反馈
提交成功!非常感谢您的反馈,我们会继续努力做到更好!