All Products
Search
Document Center

Object Storage Service:Restore objects (Harmony SDK)

Last Updated:Mar 20, 2026

Objects in the Archive, Cold Archive, and Deep Cold Archive storage classes must be restored before you can read them. Restoration is an asynchronous process: OSS creates a temporary readable copy while keeping the original archived object intact. The temporary copy is automatically deleted when the restoration period expires.

Prerequisites

Before you begin, ensure that you have:

Restore an object

The following example calls restoreObject to restore an archived object and keep it accessible for 2 days.

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

// Initialize the OSS client with STS temporary access credentials.
const client = new Client({
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,         // AccessKey ID from your STS credential
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,  // AccessKey secret from your STS credential
  securityToken: process.env.OSS_SECURITY_TOKEN,       // Security token from your STS credential
  // Region where the bucket is located, for example: oss-cn-hangzhou
  region: 'oss-cn-hangzhou',
});

const bucket = 'examplebucket';
const key = 'exampledir/example.log';

const restoreObject = async () => {
  try {
    const res = await client.restoreObject({
      bucket,
      key,
      restoreRequest: {
        // Number of days the restored copy remains accessible.
        days: 2,
      },
    });

    console.log(JSON.stringify(res));
  } catch (err) {
    if (err instanceof RequestError) {
      console.log('code: ', err.code);           // Error code
      console.log('message: ', err.message);     // Error message
      console.log('requestId: ', err.requestId); // Request ID for troubleshooting
      console.log('status: ', err.status);       // HTTP status code
      console.log('ec: ', err.ec);               // EC code
    } else {
      console.log('unknown error: ', err);
    }
  }
};

restoreObject();

Replace the placeholders in the code with your actual values:

ParameterDescriptionExample
process.env.OSS_ACCESS_KEY_IDAccessKey ID from your STS temporary access credential, read from an environment variableLTAI5tXxx
process.env.OSS_ACCESS_KEY_SECRETAccessKey secret from your STS temporary access credential, read from an environment variablexXxXxXx
process.env.OSS_SECURITY_TOKENSecurity token from your STS temporary access credential, read from an environment variableCAIXxx
examplebucketName of the bucketmy-bucket
exampledir/example.logFull path of the object to restorelogs/2025/app.log
Note: Only Archive, Cold Archive, and Deep Cold Archive objects support the restoreObject method. For supported regions and endpoints, see Regions and endpoints.

What's next

  • To learn more about the restore process and storage class behavior, see Restore objects.