Todos os produtos
Search
Central de documentação

Object Storage Service:Restaurar arquivos (SDK para Node.js)

Última atualização: Jul 03, 2026

Restaure objetos Archive ou Cold Archive antes de acessá-los. Este tópico descreve como restaurar esses objetos.

Nota

Não chame o método RestoreObject para objetos fora das classes de armazenamento Archive ou Cold Archive.

Restaurar um objeto Archive

O código a seguir demonstra como restaurar um 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 um objeto Cold Archive

O código a seguir demonstra como restaurar um 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);
  });

Referências

  • Para obter o código de exemplo completo sobre a restauração de objetos Archive e Cold Archive, consulte os exemplos no GitHub.

  • Para mais informações sobre a operação de API de restauração de objetos Archive e Cold Archive, consulte RestoreObject.