All Products
Search
Document Center

Object Storage Service:Restore files (Node.js SDK)

Last Updated:Mar 20, 2026

Archive and Cold Archive objects must be restored before they can be accessed. Use the OSS SDK for Node.js to initiate restore operations for both storage classes.

Only call RestoreObject on Archive or Cold Archive objects. Calling it on objects in other storage classes is not supported.

Prerequisites

Before you begin, ensure that you have:

  • The ali-oss package installed

  • Environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET set with valid credentials

Restore an Archive object

const OSS = require('ali-oss')

const client = new OSS({
  // Set to the region where your bucket is located, for example: oss-cn-hangzhou
  region: 'yourRegion',
  // Read credentials from environment variables
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  bucket: 'examplebucket',
});

client.restore('exampleobject.txt').then((res) => {
  console.log(res);
}).catch(err => {
  console.log(err);
});

Restore a Cold Archive object

Cold Archive objects support three restore priorities. Choose based on how quickly you need access:

PriorityRestore timeWhen to use
ExpeditedWithin 1 hourUrgent access needed
Standard2–5 hoursDefault; suitable for most use cases
Bulk5–12 hoursNon-urgent

Pass the priority using JobParameters. If JobParameters is omitted, Standard is used by default.

Use Days to specify how long the restored object remains accessible (1–7 days).

const OSS = require('ali-oss')

const client = new OSS({
  // Set to the region where your bucket is located, for example: oss-cn-hangzhou
  region: 'yourRegion',
  // Read credentials from environment variables
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  bucket: 'examplebucket',
});

const restoreOptions = {
  type: 'ColdArchive',
  JobParameters: 'Bulk',   // Expedited | Standard | Bulk
  Days: 2,                 // Number of days the object remains accessible (1–7)
};

client.restore('exampleobject.txt', restoreOptions)
  .then(res => {
    console.log(res);
  })
  .catch(err => {
    console.log(err);
  });

References