开发者社区> 问答> 正文

iOS-SDK之如何实现分片上传(二)?


完成分片上传(设置ServerCallback)


完成分片上传请求可以设置Server Callback参数,请求完成后会向指定的Server Adress发送回调请求;可通过查看返回结果的result.serverReturnJsonString,查看servercallback结果。

  1. OSSCompleteMultipartUploadRequest * complete = [OSSCompleteMultipartUploadRequest new];
  2. complete.bucketName = @"<bucketName>";
  3. complete.objectKey = @"<objectKey>";
  4. complete.uploadId = uploadId;
  5. complete.partInfos = partInfos;
  6. complete.callbackParam = @{
  7.                           @"callbackUrl": @"<server address>",
  8.                           @"callbackBody": @"<test>"
  9.                           };
  10. complete.callbackVar = @{
  11.                         @"var1": @"value1",
  12.                         @"var2": @"value2"
  13.                         };
  14. OSSTask * completeTask = [client completeMultipartUpload:complete];
  15. [[completeTask continueWithBlock:^id(OSSTask *task) {
  16.     if (!task.error) {
  17.         OSSCompleteMultipartUploadResult * result = task.result;
  18.         NSLog(@"server call back return : %@", result.serverReturnJsonString);
  19.     } else {
  20.         // ...
  21.     }
  22.     return nil;
  23. }] waitUntilFinished];


删除分片上传事件


下面代码取消了对应UploadId的分片上传请求。
  1. OSSAbortMultipartUploadRequest * abort = [OSSAbortMultipartUploadRequest new];
  2. abort.bucketName = @"<bucketName>";
  3. abort.objectKey = @"<objectKey>";
  4. abort.uploadId = uploadId;
  5. OSSTask * abortTask = [client abortMultipartUpload:abort];
  6. [abortTask waitUntilFinished];
  7. if (!abortTask.error) {
  8.     OSSAbortMultipartUploadResult * result = abortTask.result;
  9.     uploadId = result.uploadId;
  10. } else {
  11.     NSLog(@"multipart upload failed, error: %@", abortTask.error);
  12.     return;
  13. }


罗列分片


调用listParts方法获取某个上传事件所有已上传的分片。
  1. OSSListPartsRequest * listParts = [OSSListPartsRequest new];
  2. listParts.bucketName = @"<bucketName>";
  3. listParts.objectKey = @"<objectkey>";
  4. listParts.uploadId = @"<uploadid>";
  5. OSSTask * listPartTask = [client listParts:listParts];
  6. [listPartTask continueWithBlock:^id(OSSTask *task) {
  7.     if (!task.error) {
  8.         NSLog(@"list part result success!");
  9.         OSSListPartsResult * listPartResult = task.result;
  10.         for (NSDictionary * partInfo in listPartResult.parts) {
  11.             NSLog(@"each part: %@", partInfo);
  12.         }
  13.     } else {
  14.         NSLog(@"list part result error: %@", task.error);
  15.     }
  16.     return nil;
  17. }];

注:默认情况下,如果存储空间中的分片上传事件的数量大于1000,则只会返回1000个Multipart Upload信息,且返回结果中 IsTruncated 为false,并返回 NextPartNumberMarker作为下此读取的起点。

展开
收起
青衫无名 2017-10-18 14:40:04 1581 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
滴滴出行iOS端瘦身实践 立即下载
一个跨平台的云服务SDK需要什么 立即下载