Exclua tags desnecessárias de um objeto de acordo com seus requisitos. Se o versionamento estiver ativado para o bucket que armazena o objeto, o Object Storage Service (OSS) exclui as tags da versão atual do objeto por padrão. Para excluir as tags de uma versão específica, especifique o ID da versão do objeto.
Exclua tags de objeto
Se o versionamento não estiver ativado para o bucket que armazena o objeto, exclua as tags do objeto de acordo com seus requisitos. Se o versionamento estiver ativado para o bucket que armazena o objeto, o OSS exclui as tags da versão atual do objeto por padrão.
O código a seguir mostra como excluir as tags do objeto exampleobject.txt, localizado no diretório exampledir do bucket examplebucket:
const OSS = require('ali-oss')
const client = new OSS({
// Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
region: 'yourRegion',
// Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
authorizationV4: true,
// Specify the bucket name. For example, examplebucket.
bucket: 'examplebucket',
});
// Specify the full path of the object. For example, exampledir/exampleobject.txt. The full path cannot contain the bucket name.
const objectName = 'exampledir/exampleobject.txt'
// Delete the object tags.
async function deleteObjectTagging(objectName) {
try {
const result = await client.deleteObjectTagging(objectName);
console.log(result);
} catch (e) {
console.log(e);
}
}
deleteObjectTagging(objectName)
Exclua tags de uma versão específica de um objeto
Se o versionamento estiver ativado para o bucket que armazena o objeto, exclua as tags de uma versão específica do objeto. Para isso, especifique o ID da versão do objeto.
O código a seguir mostra como excluir as tags de uma versão específica do objeto exampleobject.txt, localizado no diretório exampledir do bucket examplebucket:
Para mais informações sobre como obter o ID da versão, consulte List objects (Node.js SDK).
const OSS = require('ali-oss')
const client = new OSS({
// Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
region: 'yourRegion',
// Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
authorizationV4: true,
// Specify the bucket name. For example, examplebucket.
bucket: 'examplebucket',
});
// Specify the full path of the object. For example, exampledir/exampleobject.txt. The full path cannot contain the bucket name.
const objectName = 'exampledir/exampleobject.txt'
// Specify the version ID of the object.
const versionId = 'CAEQIRiBgMDqvPqA3BciIDJhMjE4MWZkN2ViYTRmYzJhZjkxMzk2YWM2NjJk****'
// Delete the object tags.
async function deleteObjectTagging(objectName) {
try {
const options = {
versionId
};
const result = await client.deleteObjectTagging(objectName, options);
console.log(result);
} catch (e) {
console.log(e);
}
}
deleteObjectTagging(objectName)
Referências
Para obter o código de exemplo completo usado para excluir tags de objeto, consulte o GitHub.
Para obter mais informações sobre a operação da API usada para excluir tags de objeto, consulte DeleteObjectTagging.