Todos os produtos
Search
Central de documentação

Object Storage Service:Listar buckets (SDK Ruby)

Última atualização: Jul 03, 2026

Um bucket é um contêiner para 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 atual do Alibaba Cloud em todas as regiões e que atendem a condições específicas.

Listar buckets

O código a seguir mostra como listar todos os buckets em todas as regiões da sua conta.

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # The China (Hangzhou) endpoint is used as an example. Replace it with the actual endpoint.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Obtain access credentials from environment variables. Before running this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# List all buckets across all regions in your account.
buckets = client.list_buckets
buckets.each { |b| puts b.name }

Listar buckets com um prefixo especificado

O código a seguir mostra como listar buckets com o prefixo "example" em todas as regiões da sua conta.

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # The China (Hangzhou) endpoint is used as an example. Replace it with the actual endpoint.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Obtain access credentials from environment variables. Before running this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# List buckets with a specified prefix across all regions in your account.
buckets = client.list_buckets(:prefix => 'example')
buckets.each { |b| puts b.name }

Referências

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