All Products
Search
Document Center

Object Storage Service:Download an object to memory (Node.js SDK)

Last Updated:Nov 29, 2025

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

Sample code

The following sample 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 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();

References

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