Object tagging uses a key-value pair to identify objects. This topic describes how to query the tags of an object.

Sample code

The following code provides an example on how to query the tags of an object:

using Aliyun.OSS;
// 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. 
var endpoint = "yourEndpoint";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
var accessKeyId = "yourAccessKeyId";
var accessKeySecret = "yourAccessKeySecret";
// Specify the name of the bucket. Example: examplebucket. 
var bucketName = "examplebucket";
// Specify the full path of the object. The full path cannot contain the bucket name. Example: exampledir/exampleobject.txt. 
var objectName = "exampledir/exampleobject.txt";
// Create an OSSClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
    // Query the tags of the object. 
    var result = client.GetObjectTagging(bucketName,objectName);
    Console.WriteLine("get objects tagging succeeded");
    foreach (var tag in result.Tags)
    {
        Console.WriteLine("key:{0}, value:{1}", tag.Key, tag.Value);
    }
}
catch (Exception ex)
{
    Console.WriteLine("get objects tagging failed. {0}", ex.Message);
}

References

For more information about the API operation that you can call to query the tags of an object, see GetObjectTagging.