Tous les produits
Search
Centre de documentation

Object Storage Service:Restore files (Node.js SDK)

Dernière mise à jour :Aug 19, 2026

Vous devez restaurer les objets de classe de stockage Archive ou Cold Archive avant d'y accéder. Cette rubrique explique comment restaurer ces objets.

Remarque

N'appelez pas la méthode RestoreObject pour les objets qui n'appartiennent pas aux classes de stockage Archive ou Cold Archive.

Restaurer un objet Archive

Le code suivant permet de restaurer un objet Archive :

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);
})

Restaurer un objet Cold Archive

Le code suivant permet de restaurer un objet Cold Archive :

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);
  });

Références

  • Pour obtenir le code d'exemple complet montrant comment restaurer les objets Archive et Cold Archive, consultez les exemples GitHub.

  • Pour plus d'informations sur l'opération API permettant de restaurer les objets Archive et Cold Archive, consultez RestoreObject.