iOS Upload SDK

Last update:2023-02-02 10:57:22

Cloud VoD provides iOS upload SDK for you to embed in your APP, making it easier upload files from iOS mobile devices to Cloud VoD.

Getting Started

Download SDK
Source Code and Install Guide

Get the upload token and URL

Visit Get Video Upload Token for more details.

Initialization

Initialize to set the upload domain, timeout, upload concurrency and retries.

/**
 Create a Client to send upload request to Cloud VoD
 
 @param baseURL --the upload domain(required)
 @param timeout 
 @param concurrentCount --the concurrencies to do multi-part upload,range 5~10。
 @param retryTimes  */
- (instancetype _Nonnull)initWithBaseURL:(NSURL * _Nullable)baseURL
                              andTimeout:(NSTimeInterval)timeout
                         concurrentCount:(NSUInteger)concurrentCount
                              retryTimes:(NSUInteger)retryTimes;

How to Upload

Normal Upload

  WCSUploadObjectRequest *request = [[WCSUploadObjectRequest alloc] init];
  request.token = @"the upload token,get the token via get-upload-token API";
  request.fileName = @"origin name of the fie to be uploaded";
  request.key = @"file name to be displayed on Cloud VoD console, will use fileName by default";
  request.fileData = fileData; // file content to be uploaded
  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 *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 {
      // Below is the response if request successfully
      NSDictionary *responseResult = task.result.results;
    }
    return nil;
  }];

Multi-part Upload

It will take a long time to upload large files on mobile devices, and once the file upload is terminated due to any abnormality, all content need to be re-uploaded, which affects user experience. Thus, we recommend you to use Multi-part Upload when uploading large files.
Multi-part Upload is to cut a large file into multiple blocks and chunks of custom size, and then upload these blocks in parallel. If a block fails to upload, the client only needs to re-upload this block.

Note: The maximum size of each block cannot exceed 100M; the minimum size cannot be less than 4M.

 WCSUploadObjectRequest *request = [[WCSUploadObjectRequest alloc] init];
  request.token = @"the upload token,get the token via get-upload-token API";
  request.fileName = @"origin name of the fie to be uploaded";
  request.key = @"file name to be displayed on Cloud VoD console, will use fileName by default";
  request.fileData = fileData; // file content to be uploaded
  request.blockSize = 8 * 1024 * 1024; // block size
  request.chunkSize = 64 * 1024; // chunk size
  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 *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 {
      // Below is the response if request successfully
      NSDictionary *responseResult = task.result.results;
    }
    return nil;
  }];

Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!