This topic describes how to download an object to the local memory.

Sample code

The following code provides an example on how to download an object to the local memory:

const OSS = require('ali-oss');

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourregion',
  // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret'
  // Set yourbucketname to the name of your bucket. 
  bucket: 'yourbucketname', 
});

async function getBuffer () {
  try {
    const result = await client.get('object-name');
    console.log(result.content);
  } catch (e) {
    console.log(e);
  }
}

getBuffer();

References

For more information about the API operation that you can call to download objects to the local memory, see GetObject.