Use o OSS SDK for C# V2 para excluir tags de objetos em um bucket.
Pré-requisitos
O código de exemplo deste tópico usa a região China (Hangzhou) (
cn-hangzhou) como referência. Por padrão, utiliza-se um endpoint público. Se você acessar o OSS a partir de outro serviço da 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.Tags de objeto são pares chave-valor usados para gerenciar objetos. Para saber mais sobre marcação de objetos, consulte Marcação de objetos no Guia de Desenvolvimento.
Para obter detalhes sobre a operação DeleteObjectTagging, consulte DeleteObjectTagging.
Para excluir tags de objeto, é necessária a permissão
oss:DeleteObjectTagging. Para mais informações, consulte Conceder políticas de acesso personalizadas a usuários do RAM.
Código de exemplo
O código a seguir exclui as tags de um objeto específico em um bucket.
using OSS = AlibabaCloud.OSS.V2; // Create an alias for the 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 endpoint = null as string; // Optional. Specify the endpoint of the OSS service. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
var bucket = "your bucket name"; // Required. The bucket name.
var key = "your object key"; // Required. The name of the destination object.
// Load the default configurations of the 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 for the configuration.
cfg.Region = region;
// If an endpoint is specified, it overwrites the default endpoint.
if(endpoint != null)
{
cfg.Endpoint = endpoint;
}
// Create an OSS client instance using the configuration information.
using var client = new OSS.Client(cfg);
// Call the DeleteObjectTaggingAsync method to delete the tags of the destination object.
var result = await client.DeleteObjectTaggingAsync(new()
{
Bucket = bucket,
Key = key
});
// Print the result information.
Console.WriteLine("DeleteObjectTagging done"); // Indicate 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 header information.
result.Headers.ToList().ForEach(x => Console.WriteLine(x.Key + " : " + x.Value)); // Traverse and print all response headers.
Referências
Para obter o código de exemplo completo, consulte DeleteObjectTagging.cs.