All Products
Search
Document Center

Object Storage Service:Convert the storage class of an object (iOS SDK)

Last Updated:Mar 20, 2026

OSS supports five storage classes—Standard, Infrequent Access (IA), Archive, Cold Archive, and Deep Cold Archive—covering the full spectrum from hot data to cold data. Use the iOS SDK to change an object's storage class in place without re-uploading it.

Supported conversions

All conversions use a copy-in-place operation (OSSCopyObjectRequest) that overwrites the object with the new storage class. Some conversions require an extra restore step before copying.

FromToExtra step required
Standard or IAArchiveNone
Archive, Cold Archive, or Deep Cold ArchiveIARestore the object first

Prerequisites

Before you begin, ensure that you have:

  • An initialized OSSClient instance. For setup instructions, see Initialization.

Convert Standard or IA to Archive

The following example converts exampleobject.txt in the root directory of examplebucket from Standard or IA to Archive.

OSSCopyObjectRequest *copy = [OSSCopyObjectRequest new];
copy.sourceBucketName = @"examplebucket";
copy.sourceObjectKey = @"exampleobject.txt";
copy.bucketName = @"examplebucket";
copy.objectKey = @"exampleobject.txt";
// Set the target storage class.
copy.objectMeta = @{@"x-oss-storage-class" : @"Archive"};

OSSTask *task = [client copyObject:copy];
[task continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"copy object success!");
    } else {
        NSLog(@"copy object failed, error: %@", task.error);
    }
    return nil;
}];
// Uncomment the following line to block until the task completes.
// [task waitUntilFinished];

Convert Archive, Cold Archive, or Deep Cold Archive to IA

Converting out of Archive, Cold Archive, or Deep Cold Archive requires restoring the object first. The example below polls once per second to detect when restoration is complete.

The following example converts exampleobject.txt in the root directory of examplebucket from Archive to IA. To handle Cold Archive or Deep Cold Archive instead, replace isArchived with isColdArchived or isDeepColdArchived in the storage class check.

NSString *bucketName = @"examplebucket";
NSString *objectKey = @"exampleobject.txt";

// Step 1: Check the current storage class.
__block bool isArchived = false;
OSSHeadObjectRequest *headRq = [OSSHeadObjectRequest new];
headRq.bucketName = bucketName;
headRq.objectKey = objectKey;
[[[client headObject:headRq] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
    if (!task.error) {
        OSSHeadObjectResult *headRs = task.result;
        isArchived = [headRs.httpResponseHeaderFields[@"x-oss-storage-class"] isEqualToString:@"Archive"];
    } else {
        NSLog(@"head object failed, error: %@", task.error);
    }
    return nil;
}] waitUntilFinished];

// Step 2: Restore the object if it is archived.
if (isArchived) {
    OSSRestoreObjectRequest *restoreRequest = [OSSRestoreObjectRequest new];
    restoreRequest.bucketName = bucketName;
    restoreRequest.objectKey = objectKey;
    [[[client restoreObject:restoreRequest] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
        if (!task.error) {
            NSLog(@"restore object success!");
        } else {
            NSLog(@"restore object failed, error: %@", task.error);
        }
        return nil;
    }] waitUntilFinished];

    // Step 3: Poll until restoration is complete.
    // x-oss-restore is absent or set to "ongoing-request=\"true\"" while restoring.
    __block bool isRestored = false;
    do {
        sleep(1);
        headRq = [OSSHeadObjectRequest new];
        headRq.bucketName = bucketName;
        headRq.objectKey = objectKey;
        [[[client headObject:headRq] continueWithBlock:^id _Nullable(OSSTask * _Nonnull task) {
            if (!task.error) {
                OSSHeadObjectResult *headRs = task.result;
                isRestored = (headRs.httpResponseHeaderFields[@"x-oss-restore"] != nil &&
                              ![headRs.httpResponseHeaderFields[@"x-oss-restore"] isEqualToString:@"ongoing-request=\"true\""]);
            } else {
                NSLog(@"head object failed, error: %@", task.error);
            }
            return nil;
        }] waitUntilFinished];
    } while (!isRestored);
}

// Step 4: Change the storage class to IA.
OSSCopyObjectRequest *copy = [OSSCopyObjectRequest new];
copy.bucketName = bucketName;
copy.objectKey = objectKey;
copy.sourceBucketName = bucketName;
copy.sourceObjectKey = objectKey;
copy.objectMeta = @{@"x-oss-storage-class": @"IA"};

[[[client copyObject:copy] continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"copy object success!");
    } else {
        NSLog(@"copy object failed, error: %@", task.error);
    }
    return nil;
}] waitUntilFinished];

What's next