Você pode excluir tags desnecessárias de um objeto conforme necessário. Se o controle de versão estiver ativado no bucket que armazena o objeto, o Object Storage Service (OSS) exclui, por padrão, as tags da versão atual. Para excluir as tags de uma versão específica, especifique o ID da versão correspondente.
Notas
Neste tópico, utilizamos o endpoint público da região China (Hangzhou). Para acessar o OSS a partir de outros serviços da Alibaba Cloud na mesma região, use um endpoint interno. Para obter mais informações sobre as regiões e endpoints do OSS, consulte Regions and endpoints.
Este tópico mostra como criar uma instância de OSSClient com um endpoint do OSS. Para configurações alternativas, como usar um domínio personalizado ou autenticar com credenciais do Security Token Service (STS), consulte Initialization.
Para excluir as tags de um objeto, você deve ter a permissão
oss:DeleteObjectTagging. Para obter mais informações, consulte Grant a custom policy.
Excluir tags de um objeto
Se o controle de versão não estiver ativado no bucket que armazena o objeto, exclua as tags conforme necessário. Quando o controle de versão está ativado no bucket, o OSS exclui as tags da versão atual do objeto por padrão.
O código a seguir ilustra como excluir as tags do objeto exampleobject.txt localizado no diretório exampledir do bucket examplebucket:
# -*- coding: utf-8 -*-
import oss2
from oss2.models import Tagging, TaggingRule
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"
# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)
# Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt.
object_name = 'exampledir/exampleobject.txt'
# Delete the tags of the object.
result = bucket.delete_object_tagging(object_name)
print('http response status: ', result.status)
Excluir tags de uma versão específica de um objeto
Quando o controle de versão está ativado no bucket que armazena o objeto, exclua as tags de uma versão específica especificando o respectivo ID.
O exemplo abaixo demonstra como excluir as tags de uma versão específica do objeto exampleobject.txt no diretório exampledir do bucket examplebucket:
Para obter mais informações sobre como recuperar IDs de versão, consulte List objects (OSS SDK for Python 1.0).
# -*- coding: utf-8 -*-
import oss2
from oss2.models import Tagging
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"
# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)
# Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt.
object_name = 'exampledir/exampleobject.txt'
# Specify the version ID of the object.
version_id = 'CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****'
params = dict()
params['versionId'] = version_id
bucket.delete_object_tagging(object_name, params=params)
Referências
Acesse o exemplo completo de código para excluir tags de objetos em Alibaba Cloud OSS Python SDK object tagging example.
Para detalhes sobre a operação de API que exclui tags, consulte DeleteObjectTagging.