This topic describes how to obtain the tags added to an object.

The object tagging function uses a key-value pair to tag an object. For more information about the object tagging function, see Configure object tagging.

The following code provides an example on how to obtain the tags added to an object:

const OSS = require('ali-oss')

const client = new OSS({
  // This example uses the endpoint of the China (Hangzhou) region. Specify the actual endpoint based on your requirements.
  region: '<Your region>',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS, because the account has permissions on all API operations. We recommend that you use your RAM user's credentials to call API operations or perform routine operations and maintenance. To create a RAM user, log on to https://ram.console.aliyun.com.
  accessKeyId: '<Your AccessKeyId>',
  accessKeySecret: '<Your AccessKeySecret>',
});

// Obtain the tags added to the object.
async function getObjectTagging(objectName) {
  try {
    let result = await client.getObjectTagging(objectName);
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

getObjectTagging('objectName')

For more information about how to obtain the tags added to an object, see GetObjectTagging.