完成分片上传(设置ServerCallback)
完成分片上传请求可以设置Server Callback参数,请求完成后会向指定的Server Adress发送回调请求;可通过查看返回结果的result.serverReturnJsonString,查看servercallback结果。
- OSSCompleteMultipartUploadRequest * complete = [OSSCompleteMultipartUploadRequest new];
- complete.bucketName = @"<bucketName>";
- complete.objectKey = @"<objectKey>";
- complete.uploadId = uploadId;
- complete.partInfos = partInfos;
- complete.callbackParam = @{
- @"callbackUrl": @"<server address>",
- @"callbackBody": @"<test>"
- };
- complete.callbackVar = @{
- @"var1": @"value1",
- @"var2": @"value2"
- };
- OSSTask * completeTask = [client completeMultipartUpload:complete];
- [[completeTask continueWithBlock:^id(OSSTask *task) {
- if (!task.error) {
- OSSCompleteMultipartUploadResult * result = task.result;
- NSLog(@"server call back return : %@", result.serverReturnJsonString);
- } else {
- // ...
- }
- return nil;
- }] waitUntilFinished];
删除分片上传事件
下面代码取消了对应UploadId的分片上传请求。
- OSSAbortMultipartUploadRequest * abort = [OSSAbortMultipartUploadRequest new];
- abort.bucketName = @"<bucketName>";
- abort.objectKey = @"<objectKey>";
- abort.uploadId = uploadId;
- OSSTask * abortTask = [client abortMultipartUpload:abort];
- [abortTask waitUntilFinished];
- if (!abortTask.error) {
- OSSAbortMultipartUploadResult * result = abortTask.result;
- uploadId = result.uploadId;
- } else {
- NSLog(@"multipart upload failed, error: %@", abortTask.error);
- return;
- }
罗列分片
调用listParts方法获取某个上传事件所有已上传的分片。
- OSSListPartsRequest * listParts = [OSSListPartsRequest new];
- listParts.bucketName = @"<bucketName>";
- listParts.objectKey = @"<objectkey>";
- listParts.uploadId = @"<uploadid>";
- OSSTask * listPartTask = [client listParts:listParts];
- [listPartTask continueWithBlock:^id(OSSTask *task) {
- if (!task.error) {
- NSLog(@"list part result success!");
- OSSListPartsResult * listPartResult = task.result;
- for (NSDictionary * partInfo in listPartResult.parts) {
- NSLog(@"each part: %@", partInfo);
- }
- } else {
- NSLog(@"list part result error: %@", task.error);
- }
- return nil;
- }];
注:默认情况下,如果存储空间中的分片上传事件的数量大于1000,则只会返回1000个Multipart Upload信息,且返回结果中 IsTruncated 为false,并返回 NextPartNumberMarker作为下此读取的起点。