Updated on 2023-03-21 GMT+08:00

Downloading an Object

Sample code:

NSString * outfilePath = [NSTemporaryDirectory() stringByAppendingString:@"filename"];
OBSGetObjectToFileRequest *request = [[OBSGetObjectToFileRequest alloc]initWithBucketName:@"bucketname" objectKey:@"objectname" downloadFilePath:outfilePath];
// Query the download progress.
request.downloadProgressBlock = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
    NSLog(@"%0.1f%%",(float)floor(totalBytesWritten*10000/totalBytesExpectedToWrite)/100);
};
[client getObject:request completionHandler:^(OBSGetObjectResponse *response, NSError *error){
    NSLog(@"%@",response.etag);
}];
  • When you call getObject, an instance of OBSObject will be returned. This instance contains the content and properties of the object.
  • For more information, see Object Download.