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 Archive objects

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

const OSS = require('ali-oss')

const client = new OSS({
  // Set yourRegion to the endpoint of the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Specify the name of the bucket. Example: examplebucket. 
  bucket: 'examplebucket',
});

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

Restore a Cold Archive object

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

const OSS = require('ali-oss')

const client = new OSS({
  // Set yourRegion to the endpoint of the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret',
  // Specify the name of the bucket. Example: examplebucket. 
  bucket: 'examplebucket',
});
// Specify the name of the object. Example: exampleobject.txt. 
client.restore('exampleobject.txt',{type:'ColdArchive'})
  .then(res=>console.log(res))
  .catch(e=>console.log(e))

// Set type to the Cold Archive storage class. 
// Set JobParameters to the restoration priority of the object. 
// Expedited: The object is restored within one hour. 
// Standard: The object is restored within two to five hours. If the JobParameters element is not passed in, the default restoration priority is Standard. 
// Bulk: The object is restored within five to twelve hours. 
// Days is used to specify the duration in which the object can remain in the restored state. Unit: days Valid values: 1 to 7. 
//const result = await client.restore('exampleobject.txt',{type:'ColdArchive',JobParameters:'Standard',Days:2})
//.then(r=>console.log(r))

References

  • For more information about the complete sample code that is used to restore Archive or Cold Archive objects, visit GitHub.
  • For more information about the API operation that you can call to restore Archive or Cold Archive objects, see RestoreObject.