tencent cloud

Cloud Object Storage

Tag Operation

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 2026-02-02 17:19:09

Introduction

This document provides an overview of APIs and SDK sample code related to tag operations for objects.
API
Operation Name
Operation Description
Setting Tags
Setting Tags for Existing Objects
Querying Tags
Query existing object tags for a specified object.
Deleting a tag
Delete existing object tags for a specified object.

Setting Tags

Feature Overview

Setting Tags for Existing Objects (PUT Object tagging).

Example Code

// Bucket name, which consists of bucketname-appid (appid must be included), can be viewed in the COS console. https://console.tencentcloud.com/cos5/bucket
let bucket = "examplebucket-1250000000";
//The location identifier of an object in a bucket, also known as the object key
let cosPath = "exampleobject.txt";

let tagSet = new List<TagObject>();
tagSet.add(new TagObject("tag1", "value1"))
tagSet.add(new TagObject("tag2", "value2"))
let request = new PutObjectTagRequest(bucket,cosPath,tagSet);
try {
let result = await CosXmlBaseService.default().putObjectTag(request)
// result includes http headers, etc.
} catch (e) {
// Exception handling
}

Querying Tags

Feature Overview

Query existing object tags for a specified object (GET Object tagging).

Example Code

// Bucket name, which consists of bucketname-appid (appid must be included), can be viewed in the COS console. https://console.tencentcloud.com/cos5/bucket
let bucket = "examplebucket-1250000000";
//The location identifier of an object in a bucket, also known as the object key
let cosPath = "exampleobject.txt";

let request = new GetObjectTagRequest(bucket, cosPath);
try {
let result = await CosXmlBaseService.default().getObjectTag(request)
// result includes http headers, etc.
} catch (e) {
// Exception handling
}

Deleting a Tag

Feature Overview

Delete existing object tags for a specified object (DELETE Object tagging).

Example Code

// Bucket name, which consists of bucketname-appid (appid must be included), can be viewed in the COS console. https://console.tencentcloud.com/cos5/bucket
let bucket = "examplebucket-1250000000";
//The location identifier of an object in a bucket, also known as the object key
let cosPath = "exampleobject.txt";

let request = new DeleteObjectTagRequest(bucket, cosPath);
try {
let result = await CosXmlBaseService.default().deleteObjectTag(request)
// result includes http headers, etc.
} catch (e) {
// Exception handling
}


Ajuda e Suporte

Esta página foi útil?

comentários