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

Torch Object Storage

Copy page
Download PDF
Upload Object
Simple Upload (iOS SDK)
Copy page
Download PDF
Simple Upload (iOS SDK)
Through this interface, you can upload objects to a specified bucket. The uploaded content includes both data and local files.​
Data Upload​
The following code demonstrates how to upload data to the target bucket.​
​
​
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];​
​
TOSPutObjectInput *put = [TOSPutObjectInput new];​
put.tosBucket = @"bucket-name";​
put.tosKey = @"object-name";​
put.tosMeta = @{@"usermeta-key-1" : @"usermeta-value-1", @"usermeta-key-2" : @"usermeta-value-2"};​
put.tosContent = your_data; // NSData​
TOSTask *task = [client putObject:put];​
[task continueWithBlock:^id(TOSTask *task) {​
if (!task.error) {​
NSLog(@"Put object success.");​
TOSPutObjectOutput *output = task.result;​
} else {​
NSLog(@"Put object failed, error: %@" ,task.error);​
}​
return nil;​
}];​
​
Upload Local File​
The following code demonstrates how to upload a local file to the target bucket.​
​
TOSCredential *credential = [[TOSCredential alloc] initWithAccessKey:@"accesskey" secretKey:@"secretkey"];​
TOSEndpoint *tosEndpoint = [[TOSEndpoint alloc] initWithURLString:@"endpoint" withRegion:@"region"];​
TOSClientConfiguration *config = [[TOSClientConfiguration alloc] initWithEndpoint:tosEndpoint credential:credential];​
TOSClient *client = [[TOSClient alloc] initWithConfiguration:config];​
​
TOSPutObjectFromFileInput *put = [TOSPutObjectFromFileInput new];​
put.tosBucket = @"bucket-name";​
put.tosKey = @"object-name";​
put.tosMeta = @{@"usermeta-key-1" : @"usermeta-value-1", @"usermeta-key-2" : @"usermeta-value-2"};​
put.tosFilePath = @"your-file-path";​
TOSTask *task = [client putObjectFromFile:put];​
[task continueWithBlock:^id(TOSTask *task) {​
if (!task.error) {​
NSLog(@"Put object from file success.");​
TOSPutObjectFromFileOutput *output = task.result;​
} else {​
NSLog(@"Put object from file failed, error: %@" ,task.error);​
}​
return nil;​
}];​
​
​
Last updated: 2025.09.25 16:40:51