Objects in the Archive, Cold Archive, and Deep Cold Archive storage classes must be restored before you can read them. Restoration is an asynchronous process: OSS creates a temporary readable copy while keeping the original archived object intact. The temporary copy is automatically deleted when the restoration period expires.
Prerequisites
Before you begin, ensure that you have:
Objects stored in the Archive, Cold Archive, or Deep Cold Archive storage class
The
oss:RestoreObjectpermission. For details, see Grant custom permissions to a RAM user
Restore an object
The following example calls restoreObject to restore an archived object and keep it accessible for 2 days.
import Client, { RequestError } from '@aliyun/oss';
// Initialize the OSS client with STS temporary access credentials.
const client = new Client({
accessKeyId: process.env.OSS_ACCESS_KEY_ID, // AccessKey ID from your STS credential
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET, // AccessKey secret from your STS credential
securityToken: process.env.OSS_SECURITY_TOKEN, // Security token from your STS credential
// Region where the bucket is located, for example: oss-cn-hangzhou
region: 'oss-cn-hangzhou',
});
const bucket = 'examplebucket';
const key = 'exampledir/example.log';
const restoreObject = async () => {
try {
const res = await client.restoreObject({
bucket,
key,
restoreRequest: {
// Number of days the restored copy remains accessible.
days: 2,
},
});
console.log(JSON.stringify(res));
} catch (err) {
if (err instanceof RequestError) {
console.log('code: ', err.code); // Error code
console.log('message: ', err.message); // Error message
console.log('requestId: ', err.requestId); // Request ID for troubleshooting
console.log('status: ', err.status); // HTTP status code
console.log('ec: ', err.ec); // EC code
} else {
console.log('unknown error: ', err);
}
}
};
restoreObject();Replace the placeholders in the code with your actual values:
| Parameter | Description | Example |
|---|---|---|
process.env.OSS_ACCESS_KEY_ID | AccessKey ID from your STS temporary access credential, read from an environment variable | LTAI5tXxx |
process.env.OSS_ACCESS_KEY_SECRET | AccessKey secret from your STS temporary access credential, read from an environment variable | xXxXxXx |
process.env.OSS_SECURITY_TOKEN | Security token from your STS temporary access credential, read from an environment variable | CAIXxx |
examplebucket | Name of the bucket | my-bucket |
exampledir/example.log | Full path of the object to restore | logs/2025/app.log |
Note: Only Archive, Cold Archive, and Deep Cold Archive objects support the restoreObject method. For supported regions and endpoints, see Regions and endpoints.What's next
To learn more about the restore process and storage class behavior, see Restore objects.