iOS Upload SDK

최신 업데이트:2023-02-02 10:57:22

클라우드 VoD는 APP에 내장할 수 있는 iOS 업로드 SDK를 제공하여 iOS 모바일 장치에서 클라우드 VoD로 파일을 더 쉽게 업로드할 수 있도록 합니다.

시작하기

SDK 다운로드
소스 코드 및 설치 가이드

업로드 토큰 및 URL 가져오기

자세한 내용은 비디오 업로드 토큰 가져오기 를 참조하십시오.

초기화

초기화하여 업로드 도메인, 시간 초과, 업로드 동시 및 재시도를 설정합니다.

/**
 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;

업로드 방법

일반 업로드

  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;
  }];

멀티 파트 업로드

모바일로 대용량 파일을 업로드하면 시간이 오래 걸리고 파일 업로드가 이상으로 중단되면 모든 콘텐츠를 다시 업로드해야 하기 때문에 사용자 체험에 영향을 줍니다. 따라서 대용량 파일을 업로드할 때는 멀티 파트 업로드를 사용하는 것을 권장합니다.
멀티 파트 업로드는 큰 파일을 사용자 정의 크기의 여러 블록과 덩어리로 자른 후 이 블록을 병렬로 업로드하는 것입니다. 블록이 업로드되지 않으면 클라이언트는 이 블록만 다시 업로드하면 됩니다.

참고: 각 블록의 최대 크기는 100M을 초과할 수 없습니다; 최소 크기는 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;
  }];
이 문서의 내용이 도움이 되었습니까?
아니오
정상적으로 제출되었습니다.피드백을 주셔서 감사합니다.앞으로도 개선을 위해 노력하겠습니다.