Todos os produtos
Search
Central de documentação

Object Storage Service:Obter informações do bucket (OSS SDK para C# V2)

Última atualização: Jul 03, 2026

Use o OSS SDK para C# para consultar detalhes do bucket, como status de monitoramento de acesso, região, data de criação, ID do proprietário, classe de armazenamento, endpoints, status de replicação entre regiões e status de versionamento.

Precauções

  • O código de exemplo neste tópico usa a região China (Hangzhou) (ID: cn-hangzhou) como exemplo. Por padrão, o OSS SDK utiliza o endpoint público. Para acessar o OSS a partir de outros serviços do Alibaba Cloud na mesma região, use um endpoint interno. Para mais informações sobre as regiões e endpoints compatíveis com o OSS, consulte Regiões e endpoints do OSS.

  • Para obter informações do bucket, você deve ter a permissão oss:GetBucketInfo. Para mais informações, consulte Conceder permissões personalizadas a um usuário RAM.

Código de exemplo

O código de exemplo a seguir obtém informações do bucket:

using OSS = AlibabaCloud.OSS.V2; // Create an alias for Alibaba Cloud OSS SDK to simplify subsequent use.

var region = "cn-hangzhou"; // Required. Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.
var bucket = "your bucket name";  // Required. Specify the name of the destination bucket.
var endpoint = null as string;  // Optional. Specify the endpoint used to access OSS. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.

// Load the default configurations of OSS SDK. The configurations automatically read credential information (such as an AccessKey pair) from environment variables.
var cfg = OSS.Configuration.LoadDefault();
// Explicitly configure the SDK to obtain credentials from environment variables for identity verification. The format is OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
cfg.CredentialsProvider = new OSS.Credentials.EnvironmentVariableCredentialsProvider();
// Specify the region of the bucket in the configurations.
cfg.Region = region;
// If an endpoint is specified, it overwrites the default endpoint.
if(endpoint != null)
{
    cfg.Endpoint = endpoint;
}

// Create an OSS client instance based on the configurations.
using var client = new OSS.Client(cfg);

// Call the GetBucketInfoAsync method to obtain the basic information about the specified bucket.
var result = await client.GetBucketInfoAsync(new OSS.Models.GetBucketInfoRequest()
{
    Bucket = bucket
});

// Print the result.
Console.WriteLine("GetBucketInfo done");  // A message indicating that the operation is complete.
Console.WriteLine($"StatusCode: {result.StatusCode}");  // The HTTP status code.
Console.WriteLine($"RequestId: {result.RequestId}");  // The request ID, which is used for troubleshooting in Alibaba Cloud.
Console.WriteLine("Response Headers:");  // The response headers.
result.Headers.ToList().ForEach(x => Console.WriteLine(x.Key + " : " + x.Value));  // Traverse and print all response headers.
Console.WriteLine($"Location: {result.BucketInfo!.Location}");  // Print the region of the bucket.
Console.WriteLine($"StorageClass: {result.BucketInfo!.StorageClass}");  // Print the storage class of the bucket.
Console.WriteLine($"IntranetEndpoint: {result.BucketInfo!.IntranetEndpoint}");  // Print the internal endpoint of the bucket.
Console.WriteLine($"ExtranetEndpoint: {result.BucketInfo!.ExtranetEndpoint}");  // Print the public endpoint of the bucket.

Lista de informações comuns do bucket

Parâmetro

Descrição

BucketInfo.Name

O nome do bucket.

BucketInfo.AccessMonitor

O status de monitoramento de acesso do bucket.

BucketInfo.Location

A região onde o bucket está localizado.

BucketInfo.CreationDate

A data de criação do bucket.

BucketInfo.ExtranetEndpoint

O endpoint público do bucket.

BucketInfo.IntranetEndpoint

O endpoint interno para acessar o bucket de uma instância ECS na mesma região.

BucketInfo.Owner

Inclui os seguintes subparâmetros:

BucketInfo.Owner.ID: O ID do usuário proprietário do bucket.

BucketInfo.StorageClass

A classe de armazenamento do bucket.

BucketInfo.Versioning

O status de versionamento do bucket.

BucketInfo.CrossRegionReplication

O status de replicação entre regiões do bucket.

Referências

  • Para mais informações sobre buckets, consulte Buckets.

  • Para o código de exemplo completo, consulte GetBucketInfo.cs.