Tüm Ürünler
Search
Belge Merkezi

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

Son Güncelleme:Oct 01, 2026

Bu konuda, bir nesnenin yerel belleğe nasıl indirileceği açıklanmaktadır.

Örnek kod

Aşağıdaki örnek kodda, bir nesnenin yerel belleğe indirilmesi gösterilmektedir:

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();

İlgili bilgiler

Nesneleri yerel belleğe indirmek için çağrılabilen API işlemi hakkında daha fazla bilgi edinmek için bkz. GetObject.