Todos los productos
Search
Centro de documentos

Object Storage Service:Restaurar archivos (SDK de Node.js)

Última actualización: Sep 03, 2026

Debe restaurar los objetos Archive o Cold Archive antes de acceder a ellos. Este tema describe cómo restaurar objetos Archive y Cold Archive.

Nota

No invoque el método RestoreObject para objetos que no pertenezcan a las clases de almacenamiento Archive o Cold Archive.

Restaurar un objeto Archive

El siguiente código muestra cómo restaurar un objeto 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);
})

Restaurar un objeto Cold Archive

El siguiente código muestra cómo restaurar un objeto 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);
  });

Referencias

  • Para ver el código de ejemplo completo sobre cómo restaurar objetos Archive y Cold Archive, consulte los ejemplos en GitHub.

  • Para obtener más información sobre la operación de API para restaurar objetos Archive y Cold Archive, consulte RestoreObject.