You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Upload Object
Multipart Upload (iOS SDK)
Copy page
Download PDF
Multipart Upload (iOS SDK)
For larger objects, the object can be divided into multiple data blocks (parts) and uploaded separately. Finally, the CompleteMultipartUpload operation is invoked to merge the uploaded data blocks into a single object.​
Multipart Upload Procedure​
You can perform multipart upload of objects by following these steps:​
  1. CreateMultipartUpload initializes a multipart upload task.​
  1. Multipart upload is performed using UploadPart.​
  1. All parts are merged into a single object using CompleteMultipartUpload.​
Sample Code​
The following code demonstrates how to upload an object in parts using the multipart interface.​
​
​
TOSCredential *credential = [[TOSCredential alloc] initWithAccessKey:@"accesskey" secretKey:@"secretkey" securityToken:@"securityToken"];​
TOSEndpoint *tosEndpoint = [[TOSEndpoint alloc] initWithURLString:@"endpoint" withRegion:@"region"];​
TOSClientConfiguration *config = [[TOSClientConfiguration alloc] initWithEndpoint:tosEndpoint credential:credential];​
TOSClient *client = [[TOSClient alloc] initWithConfiguration:config];​
​
// 1. CreateMultipartUpload​
TOSCreateMultipartUploadInput *create = [TOSCreateMultipartUploadInput new];​
create.tosBucket = @"bucket-name";​
create.tosKey = @"object-name";​
​
TOSTask *task = [client createMultipartUpload:create];​
[task waitUntilFinished];​
TOSCreateMultipartUploadOutput *createOutput = task.result;​
​
// 2. UploadPart​
NSMutableArray *uploadedParts = [NSMutableArray array];​
for (int i = 1; i <= your_chunck_count; i++) {​
TOSUploadPartInput *upload = [TOSUploadPartInput new];​
upload.tosKey = createOutput.tosKey;​
upload.tosBucket = createOutput.tosBucket;​
upload.tosUploadID = createOutput.tosUploadID;​
upload.tosPartNumber = i;​
upload.tosContent = your_chunck_data;​
task = [client uploadPart:upload];​
[task waitUntilFinished];​
TOSUploadPartOutput *uploadOutput = task.result;​
​
TOSUploadedPart *uploadedPart = [TOSUploadedPart new];​
uploadedPart.tosETag = uploadOutput.tosETag;​
uploadedPart.tosPartNumber = uploadOutput.tosPartNumber;​
​
[uploadedParts addObject:uploadedPart];​
}​
​
// 3. CompleteMultipartUpload​
TOSCompleteMultipartUploadInput *complete = [TOSCompleteMultipartUploadInput new];​
complete.tosBucket = createOutput.tosBucket;​
complete.tosKey = createOutput.tosKey;​
complete.tosUploadID = createOutput.tosUploadID;​
complete.tosParts = uploadedParts;​
task = [client completeMultipartUpload:complete];​
[task continueWithBlock:^id(TOSTask *task) {​
if (!task.error) {​
TOSCompleteMultipartUploadOutput *completeOutput = task.result;​
} else {​
}​
return nil;​
}];​
​
​
Last updated: 2025.09.25 16:40:51