Todos os produtos
Search
Central de documentação

Object Storage Service:Criar um bucket (C# SDK V2)

Última atualização: Sep 22, 2026

Buckets são contêineres que armazenam objetos no OSS. Crie um bucket com o OSS SDK for C# V2.

Permissões

Por padrão, uma conta Alibaba Cloud tem permissões totais. Usuários RAM ou funções RAM vinculados a essa conta não possuem permissões iniciais. A conta Alibaba Cloud ou o administrador deve conceder as permissões de operação por meio de RAM policies ou Bucket Policy.

API

Action

Description

PutBucket

oss:PutBucket

Cria um bucket.

oss:PutBucketAcl

Necessária para modifique a ACL do bucket após a criação.

Precauções

  • O código de exemplo usa a região China (Hangzhou) (cn-hangzhou) e o endpoint público por padrão. Para acessar o OSS a partir de outros serviços da Alibaba Cloud na mesma região, utilize um endpoint interno listado em Regions and endpoints.

  • A partir das 10:00:00 (UTC+8) de 13 de outubro de 2025, o OSS ativará gradualmente o recurso Block public access por padrão para buckets criados via chamadas de API, OSS SDKs ou ossutil em todas as regiões. Para verificar a data de vigência da alteração em cada região, consulte Announcement. Com esse recurso ativo, não é possível conceder permissões de acesso público, incluindo ACLs public-read ou public-read-write e políticas de bucket que permitam acesso público. Se o seu cenário exigir acesso público, desative o bloqueio de acesso público após criar o bucket.

Código de exemplo

O código a seguir cria um bucket com a classe de armazenamento Standard padrão.

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 in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
var bucket = "your bucket name";  // Required. Specify the name of the bucket to be created.
var endpoint = null as string;  // Optional. Specify the domain name used to access OSS. For example, if the bucket is located 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 AccessKey) from environment variables.
var cfg = OSS.Configuration.LoadDefault();
// Explicitly set the use of environment variables to obtain credentials for identity verification (format: OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET).
cfg.CredentialsProvider = new OSS.Credentials.EnvironmentVariableCredentialsProvider();
// Set the region of the bucket in the configurations.
cfg.Region = region;
// If an endpoint is specified, overwrite the default endpoint.
if(endpoint != null)
{
    cfg.Endpoint = endpoint;
}

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

// Call the PutBucketAsync method to create a new bucket. The storage class is Standard.
var result = await client.PutBucketAsync(new OSS.Models.PutBucketRequest()
{
    Bucket = bucket
});

// Print the creation result.
Console.WriteLine("PutBucket done");  // The operation is complete.
Console.WriteLine($"StatusCode: {result.StatusCode}");  // HTTP status code
Console.WriteLine($"RequestId: {result.RequestId}");  // RequestId, which is used by Alibaba Cloud to troubleshoot issues.
Console.WriteLine("Response Headers:");  // Response header information
result.Headers.ToList().ForEach(x => Console.WriteLine(x.Key + " : " + x.Value));  // Traverse and print all response headers.

Referências

Código de exemplo completo: PutBucket.cs.