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-osspackage installedEnvironment variables
OSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETset 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:
| Priority | Restore time | When to use |
|---|---|---|
| Expedited | Within 1 hour | Urgent access needed |
| Standard | 2–5 hours | Default; suitable for most use cases |
| Bulk | 5–12 hours | Non-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);
});