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

Torch Object Storage

Copy page
Download PDF
Download Object
Downloadable Items (iOS SDK)
Copy page
Download PDF
Downloadable Items (iOS SDK)
This interface enables downloading objects from a specified bucket. Before using this interface, please ensure that you have read access to this object.​
Download Object and Read Data​
The following code demonstrates how to download an object and read its data.​
​
​
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];​
​
TOSGetObjectInput *get = [TOSGetObjectInput new];​
get.tosBucket = @"bucket-name";​
get.tosKey = @"object-name";​
TOSTask *task = [client getObject:get];​
[task continueWithBlock:^id(TOSTask *task) {​
if (!task.error) {​
NSLog(@"Get object success.");​
TOSGetObjectOutput *output = task.result;​
NSData *date = output.tosContent;​
} else {​
NSLog(@"Get object failed, error: %@" ,task.error);​
}​
return nil;​
}];​
​
Download data within a specified range of the object​
If you only need to read a specific range of data from an object, you can set the Range to read data within the specified range of the object. The following code demonstrates how to download data within the Range specified for the object.​
​
​
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];​
​
​
TOSGetObjectInput *get = [TOSGetObjectInput new];​
get.tosBucket = @"bucket-name";​
get.tosKey = @"object-name";​
get.tosRangeStart s= @1;​
get.tosRangeEnd = @100;​
TOSTask *task = [client getObject:get];​
[task continueWithBlock:^id(TOSTask *task) {​
if (!task.error) {​
NSLog(@"Get object success.");​
TOSGetObjectOutput *output = task.result;​
NSData *date = output.tosContent;​
} else {​
NSLog(@"Get object failed, error: %@" ,task.error);​
}​
return nil;​
}];​
​
Download Object to File​
The following code demonstrates how to download an object and save it to a local file.​
​
​
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];​
​
TOSGetObjectToFileInput *get = [TOSGetObjectToFileInput new];​
get.tosBucket = @"bucket-name";​
get.tosKey = @"object-name";​
get.tosFilePath = your_local_filepath;​
TOSTask *task = [client getObjectToFile:get];​
[task continueWithBlock:^id(TOSTask *task) {​
if (!task.error) {​
NSLog(@"Get object to file success.");​
TOSGetObjectToFileOutput *output = task.result;​
} else {​
NSLog(@"Get object to file failed, error: %@" ,task.error);​
}​
return nil;​
}];​
​
​
Last updated: 2025.09.25 16:40:51