All Products
Search
Document Center

Object Storage Service:Restore objects

Last Updated:Nov 11, 2024

You must restore an Archive object or a Cold Archive object before you can read the object. This topic describes how to restore an Archive object or a Cold Archive object.

Note

Do not call the RestoreObject operation on an object whose storage class is not Archive or Cold Archive.

Restore an Archive object

The following sample code provides an example on how to restore an Archive object:

const OSS = require('ali-oss')

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the name of the bucket. Example: examplebucket. 
  bucket: 'examplebucket',
});

// Specify the name of the Archive object that you want to restore. Example: exampleobject.txt. 
client.restore('exampleobject.txt').then((res) => {
    console.log(res);
}).catch(err => {
    console.log(err);
})

Restore a Cold Archive object

The following sample code provides an example on how to restore a Cold Archive object:

const OSS = require('ali-oss')

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the name of the bucket. Example: examplebucket. 
  bucket: 'examplebucket',
});

const restoreOptions = {
  // Specify Cold Archive as the storage class. 
  type: 'ColdArchive', 
  // Set JobParameters to specify a restoration priority for the object. 
  // Expedited: The object is restored within 1 hour. 
  // Standard: The object is restored within 2 to 5 hours. If you leave JobParameters empty, Standard is used as the restoration priority. 
  // Bulk: The object is restored within 5 to 12 hours. 
  JobParameters: 'Bulk', 
  // The Days parameter is used to specify the duration in which the object can remain in the restored state. Unit: days. Valid values: 1 to 7. 
  Days: 2,
};

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

References

  • For the complete sample code that is used to restore an Archive or Cold Archive object, visit GitHub.

  • For more information about the API operation that you can call to restore an Archive object or a Cold Archive object, see RestoreObject.