All Products
Search
Document Center

Object Storage Service:Restore objects (Harmony SDK)

Last Updated:Sep 21, 2026

Objects in the Archive, Cold Archive, and Deep Cold Archive storage classes must be restored before you can read them. When an object is restored, a temporary copy of the object is created. The original archived object remains. After the restoration period expires, the temporary copy is automatically deleted. This topic describes how to use the OSS Harmony software development kit (SDK) to restore Archive, Cold Archive, and Deep Cold Archive objects.

Precautions

  • Only objects in the Archive, Cold Archive, and Deep Cold Archive storage classes support the RestoreObject method.

  • For more information about the regions and endpoints that OSS supports, see Regions and endpoints.

  • To restore an object, you must have the oss:RestoreObject permission. For more information, see Grant custom permissions to a RAM user.

Sample code

Use the following code to restore an Archive, Cold Archive, or Deep Cold Archive object:

import Client, { RequestError } from '@aliyun/oss';

// Create an OSS client instance.
const client = new Client({
  // Replace with the Access Key ID for your STS temporary access credential.
  accessKeyId: 'yourAccessKeyId',
  // Replace with the Access Key Secret for your STS temporary access credential.
  accessKeySecret: 'yourAccessKeySecret',
  // Replace with the Security Token for your STS temporary access credential.
  securityToken: 'yourSecurityToken',
  // Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'oss-cn-hangzhou',
});

// Specify the name of the bucket. Replace with your actual bucket name.
const bucket = 'yourBucketName';
// Specify the name of the object to restore. Replace with your actual object name.
const key = 'yourObjectName';

/**
 * Restore an archived object.
 * Use the restoreObject method to restore an object from the Archive or Cold Archive storage class to a readable state.
 */
const restoreObject = async () => {
  try {
    // Call the restoreObject method to restore the archived object in the specified bucket.
    const res = await client.restoreObject({
      bucket, // The name of the bucket.
      key,    // The name of the object.
      restoreRequest: {
        days: 2, // The number of days that you want the restored object to be available.
      },
    });

    // Print the restoration result.
    console.log(JSON.stringify(res));
  } catch (err) {
    // Catch exceptions that occur during the request.
    if (err instanceof RequestError) {
      // If the error is a known type, print the error code, error message, request ID, status code, and EC code.
      console.log('code: ', err.code); // The error code.
      console.log('message: ', err.message); // The error message.
      console.log('requestId: ', err.requestId); // The request ID.
      console.log('status: ', err.status); // The HTTP status code.
      console.log('ec: ', err.ec); // The error code.
    } else {
      // Print other unknown types of errors.
      console.log('unknown error: ', err);
    }
  }
};

// Call the restoreObject function to restore the archived object.
restoreObject();

References