Todos os produtos
Search
Central de documentação

Object Storage Service:List buckets (OSS SDK for Node.js)

Última atualização: Sep 23, 2026

Um bucket é um contêiner de objetos armazenados no Object Storage Service (OSS). Todos os objetos no OSS estão contidos em buckets. Os buckets são listados em ordem alfabética. Você pode listar os buckets que pertencem à conta Alibaba Cloud atual em todas as regiões e que atendam a condições específicas.

Listar todos os buckets de uma conta Alibaba Cloud

O exemplo de código a seguir demonstra como listar buckets em todas as regiões da conta Alibaba Cloud atual:

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',
  // Obtain access credentials from environment variables. Before running this code, ensure 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 name of your bucket.
  bucket: 'yourBucketName',
});

async function listBuckets() {
  try {
    // List all buckets in all regions within the current Alibaba Cloud account. 
    const result = await client.listBuckets();
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

listBuckets();

Listar buckets cujos nomes contêm um prefixo especificado

Veja a seguir um exemplo de código para listar buckets cujos nomes contêm o prefixo example em todas as regiões da conta Alibaba Cloud atual:

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',  
  // Obtain access credentials from environment variables. Before running this code, ensure 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.
  bucket: 'yourBucketName',
});

async function listBuckets() {
  try {
    const result = await client.listBuckets({
      // Specify the prefix that is contained in the names of the buckets that you want to list. 
      prefix: 'example' 
    });
    // List the buckets whose names contain the specified prefix in all regions within the current Alibaba Cloud account. 
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

listBuckets();

Listar buckets cujos nomes são alfabeticamente posteriores ao bucket especificado por marker

O trecho de código abaixo ilustra como listar buckets cujos nomes são alfabeticamente posteriores ao bucket chamado examplebucket em todas as regiões da conta Alibaba Cloud atual:

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',  
  // Obtain access credentials from environment variables. Before running this code, ensure 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.
  bucket: 'yourBucketName',
});

async function listBuckets() {
  try {
    const result = await client.listBuckets({
      // Specify the value of marker. 
      marker: 'examplebucket' 
    });
    // List the buckets whose names are alphabetically after examplebucket in all regions within the current Alibaba Cloud account. 
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

listBuckets();

Listar um número específico de buckets

Utilize o exemplo de código a seguir para listar os buckets em todas as regiões da conta Alibaba Cloud atual e definir o número máximo de buckets a serem listados como 500:

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',
  // Obtain access credentials from environment variables. Before running this code, ensure 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.
  bucket: 'yourBucketName',
});

async function listBuckets() {
  try {
    const result = await client.listBuckets({
      // Specify the max-keys parameter. This parameter is used to specify the maximum number of buckets to be listed. The value of max-keys cannot exceed 1000. By default, if max-keys is not specified, up to 100 buckets are returned. 
      // List 500 buckets. 
      'max-keys': 500
    });
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

listBuckets();

Referências

  • Para acessar o código de exemplo completo usado para listar buckets, visite o GitHub.

  • Para obter mais informações sobre a operação de API para listar buckets, consulte ListBuckets (GetService).