In a versioned Object Storage Service (OSS) bucket, the storage classes of different versions of an object can be different. By default, when you call the RestoreObject operation to restore an object, the current version of the object is restored. You can specify a version ID in the request to restore a specific version of an object.
Sample code
The following sample code provides an example on how to restore an 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,
// Specify the name of the bucket.
bucket: 'yourbucketname'
});
const name = 'yourobjectName'
// Restore the specified object version.
const versionId = 'your versionId'
async function restore() {
const result = await client.restore(name, {
versionId
});
console.log(result);
}
restore();
References
For more information about the API operation that you can call to restore an object, see RestoreObject.