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, em todas as regiões, os buckets da conta atual da Alibaba Cloud que atendam 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 específico
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 da API ListBuckets, consulte ListBuckets (GetService).