Downloading an Archive Object

If you want to download an Archive object, you need to restore the object first. Three restore options are supported, as described in the following table.

Option

Description

Value in OBS iOS SDK

Expedited

Data can be restored within 1 to 5 minutes.

OBSRestoreTierExpedited

Standard

Data can be restored within 3 to 5 hours. This is the default option.

OBSRestoreTierStandard

You can call OBSRestoreObjectRequest to restore Archive objects. Sample code is as follows:

static OBSClient *client;
NSString *endPoint = @"your-endpoint";
NSString *SK = @"*** Provide your Secret Key ***";
NSString *AK = @"*** Provide your Access Key ***";
    
// Initialize identity authentication.
OBSStaticCredentialProvider *credentialProvider = [[OBSStaticCredentialProvider alloc] initWithAccessKey:AK secretKey:SK];
    
//Initialize service configuration.
OBSServiceConfiguration *conf = [[OBSServiceConfiguration alloc] initWithURLString:endPoint credentialProvider:credentialProvider];
    
// Initialize an instance of OBSClient.
client = [[OBSClient alloc] initWithConfiguration:conf];
    
// Restore an object.
OBSRestoreObjectRequest *request = [[OBSRestoreObjectRequest alloc]initWithBucketName:@"bucketname" objectKey:@"objectname" storeDays:[NSNumber numberWithInt:30]]; //1 to 30
request.restoreTier = OBSRestoreTierExpedited;
    
OBSBFTask *task = [ self.client restoreObject:request completionHandler:^(OBSRestoreObjectResponse *response, NSError *error){
    NSLog(@"%@",response);
}];
    
// Wait until the object is restored.
sleep(6*60);
    
// Download an object.
NSString * outfilePath = [NSTemporaryDirectory() stringByAppendingString:@"filename"];
OBSGetObjectToFileRequest *request1 = [[OBSGetObjectToFileRequest alloc]initWithBucketName:@"bucketname" objectKey:@"objectname" downloadFilePath:outfilePath];
request1.downloadProgressBlock = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
    NSLog(@"%0.1f%%",(float)floor(totalBytesWritten*10000/totalBytesExpectedToWrite)/100);
};
    
[client getObject:request1 completionHandler:^(OBSGetObjectResponse *response, NSError *error){
    NSLog(@"%@",response.etag);
}];