Este tópico descreve como baixar um objeto para a memória local.
Código de exemplo
O exemplo a seguir mostra como baixar um objeto para a memória local:
const OSS = require('ali-oss');
const client = new OSS({
// Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to oss-cn-hangzhou.
region: 'yourregion',
// Obtain access credentials from environment variables. Before you run this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
authorizationV4: true,
// Specify the name of the bucket.
bucket: 'yourbucketname',
});
async function getBuffer () {
try {
const result = await client.get('object-name');
console.log(result.content);
} catch (e) {
console.log(e);
}
}
getBuffer();
Referências
Para mais informações sobre a operação de API usada para baixar objetos na memória local, consulte GetObject.