tencent cloud

All product documents
Cloud Object Storage
Bucket Tagging
Last updated: 2024-02-02 12:12:58
Bucket Tagging
Last updated: 2024-02-02 12:12:58

Overview

This document provides an overview of APIs and SDK code samples related to bucket tagging.
API
Operation
Description
Setting bucket tags
Sets tags for an existing bucket
Querying bucket tags
Queries the existing tags of a bucket
Deleting bucket tags
Deletes a specified bucket tag

Setting a bucket tag

API description

This API (PUT Bucket tagging) is used to set tags for an existing bucket.

Method prototype

CosResult PutBucketTagging(const PutBucketTaggingReq& request, PutBucketTaggingResp* response);

Sample request

qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000";
qcloud_cos::PutBucketTaggingReq req(bucket_name);
qcloud_cos::PutBucketTaggingResp resp;

std::vector<Tag> tagset;
Tag tag1;
tag1.SetKey("age");
tag1.SetValue("19");

Tag tag2;
tag2.SetKey("name");
tag2.SetValue("xiaoming");
tagset.push_back(tag1);
tagset.push_back(tag2);
req.SetTagSet(tagset);

qcloud_cos::CosResult result = cos.PutBucketTagging(req, &resp);

if (result.IsSucc()) {
// Request successful
} else {
// Request failed. You can call the CosResult member functions to output the error information, such as requestID.
}

Parameter description

Parameter
Description
Type
Required
req
Request of the PutBucketTagging operation
PutBucketTaggingReq
Yes
resp
Response of the PutBucketTagging operation
PutBucketTaggingResp
Yes
PutBucketTaggingReq provides the following method:
void SetTagSet(std::vector<Tag>& tagset) // Set tagging.
Tag provides the following methods:
class Tag {
void SetKey(const std::string key); // Set the key.
void SetValue(const std::string value); // Set the value.

Querying Bucket Tags

API description

This API (GET Bucket tagging) is used to query the existing tags of a bucket.

Method prototype

CosResult CosAPI::GetBucketTagging(const GetBucketTaggingReq& request, GetBucketTaggingResp* response);

Sample request

qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000";
qcloud_cos::GetBucketTaggingReq req(bucket_name);
qcloud_cos::GetBucketTaggingResp resp;

qcloud_cos::CosResult result = cos.GetBucketTagging(req, &resp);

if (result.IsSucc()) {
// Request successful. You can use the method of `resp` to obtain the bucket tags.
} else {
// Request failed. You can call the CosResult member functions to output the error information, such as requestID.
}
GetBucketTaggingResp provides the following method to obtain the bucket tags:
std::vector<Tag> GetTagSet() const;

Parameter description

Parameter
Description
Type
Required
req
Request of the GetBucketTagging operation
GetBucketTaggingReq
Yes
resp
Response of the GetBucketTagging operation
GetBucketTaggingResp
Yes

Deleting Bucket Tags

API description

This API (DELETE Bucket tagging) is used to delete the existing tags of a bucket.

Method prototype

CosResult CosAPI::DeleteBucketTagging(const DeleteBucketTaggingReq& request, DeleteBucketTaggingResp* response);

Sample request

qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000";
qcloud_cos::DeleteBucketTaggingReq req(bucket_name);
qcloud_cos::DeleteBucketTaggingResp resp;

qcloud_cos::CosResult result = cos.DeleteBucketTagging(req, &resp);

if (result.IsSucc()) {
// Request successful
} else {
// Request failed. You can call the CosResult member functions to output the error information, such as requestID.
}

Parameter description

Parameter
Description
Type
Required
req
Request of the DeleteBucketTagging operation
DeleteBucketTaggingReq
Yes
resp
Response of the DeleteBucketTagging operation
DeleteBucketTaggingResp
Yes
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon