You must restore Archive or Cold Archive objects before you can access them. This topic describes how to restore Archive and Cold Archive objects.
Note
Do not call the RestoreObject method for objects that are not in the Archive or Cold Archive storage classes.
Restore an Archive object
The following code shows how to restore an Archive object:
const OSS = require('ali-oss')
const client = new OSS({
// Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set 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 set.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
authorizationV4: true,
// Specify the bucket name. For example, examplebucket.
bucket: 'examplebucket',
});
// Specify the name of the Archive object to restore. For 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 shows how to restore a Cold Archive object:
const OSS = require('ali-oss')
const client = new OSS({
// Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set 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 set.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
authorizationV4: true,
// Specify the bucket name. For example, examplebucket.
bucket: 'examplebucket',
});
const restoreOptions = {
// Specify the Cold Archive storage class.
type: 'ColdArchive',
// Use JobParameters to specify the restoration priority.
// Expedited: The object is restored within 1 hour.
// Standard: The object is restored within 2 to 5 hours. If you do not specify JobParameters, Standard is used by default.
// Bulk: The object is restored within 5 to 12 hours.
JobParameters: 'Bulk',
// Use Days to specify the number of days for which the restored object remains accessible. The value can be from 1 to 7.
Days: 2,
};
client.restore('exampleobject.txt', restoreOptions)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});References
For complete sample code that shows how to restore Archive and Cold Archive objects, see the GitHub examples.
For more information about the API operation to restore Archive and Cold Archive objects, see RestoreObject.