Restore objects (iOS SDK)
Objects in Archive, Cold Archive, and Deep Cold Archive storage classes are not immediately accessible and must be restored before you can read them. This topic describes how to restore these objects using the iOS SDK.
Prerequisites
Before you begin, ensure that you have:
-
An OSSClient instance. For more information, see Initialization.
-
An object stored in Archive, Cold Archive, or Deep Cold Archive storage class
Sample code
The following code shows how to restore an Archive, Cold Archive, or Deep Cold Archive object named exampleobject.txt from a bucket named examplebucket:
OSSRestoreObjectRequest *request = [OSSRestoreObjectRequest new];
// Bucket containing the archived object
request.bucketName = @"examplebucket";
// Full path of the object (do not include the bucket name)
request.objectKey = @"exampleobject.txt";
OSSTask *restoreObjectTask = [client restoreObject:request];
[restoreObjectTask continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
if (!task.error) {
NSLog(@"Restore request submitted successfully");
// Note: The object is not immediately accessible.
// Check restoration status before attempting to read.
} else {
NSLog(@"Restore request failed: %@", task.error);
// Handle specific errors (see Error handling section)
}
return nil;
}];
// Use synchronous blocking if you need to wait for request submission to complete
// Not recommended for UI thread as it blocks execution
// [restoreObjectTask waitUntilFinished];
Important: Submitting a restore request does not mean the object is immediately accessible. The restoration process runs asynchronously and takes time based on the storage class.
References
-
For the complete API reference, see RestoreObject
-
For information about initializing an OSSClient instance, see Initialization