Restore objects (iOS SDK)

Updated at:

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

  • The oss:RestoreObject permission for the bucket

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.

Error handling

Common errors when restoring objects:

Error code Description Solution
NoSuchKey The specified object does not exist Verify the object key and bucket name
OperationNotSupported The object does not support restoration because it is not in an archived storage class Verify that the object's storage class is Archive, Cold Archive, or Deep Cold Archive. Only archived objects need restoration.
RestoreAlreadyInProgress A restoration request for this object is already in progress Wait for the existing restoration to complete

References