tencent cloud

Cloud Object Storage

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Overview
Features
Use Cases
Strengths
Concepts
Regions and Access Endpoints
Specifications and Limits
Service Regions and Service Providers
Billing
Billing Overview
Billing Method
Billable Items
Free Tier
Billing Examples
Viewing and Downloading Bill
Payment Overdue
FAQs
Getting Started
Console
Getting Started with COSBrowser
User Guide
Creating Request
Bucket
Object
Data Management
Batch Operation
Global Acceleration
Monitoring and Alarms
Operations Center
Data Processing
Content Moderation
Smart Toolbox
Data Processing Workflow
Application Integration
User Tools
Tool Overview
Installation and Configuration of Environment
COSBrowser
COSCLI (Beta)
COSCMD
COS Migration
FTP Server
Hadoop
COSDistCp
HDFS TO COS
GooseFS-Lite
Online Tools
Diagnostic Tool
Use Cases
Overview
Access Control and Permission Management
Performance Optimization
Accessing COS with AWS S3 SDK
Data Disaster Recovery and Backup
Domain Name Management Practice
Image Processing
Audio/Video Practices
Workflow
Direct Data Upload
Content Moderation
Data Security
Data Verification
Big Data Practice
COS Cost Optimization Solutions
Using COS in the Third-party Applications
Migration Guide
Migrating Local Data to COS
Migrating Data from Third-Party Cloud Storage Service to COS
Migrating Data from URL to COS
Migrating Data Within COS
Migrating Data Between HDFS and COS
Data Lake Storage
Cloud Native Datalake Storage
Metadata Accelerator
GooseFS
Data Processing
Data Processing Overview
Image Processing
Media Processing
Content Moderation
File Processing Service
File Preview
Troubleshooting
Obtaining RequestId
Slow Upload over Public Network
403 Error for COS Access
Resource Access Error
POST Object Common Exceptions
API Documentation
Introduction
Common Request Headers
Common Response Headers
Error Codes
Request Signature
Action List
Service APIs
Bucket APIs
Object APIs
Batch Operation APIs
Data Processing APIs
Job and Workflow
Content Moderation APIs
Cloud Antivirus API
SDK Documentation
SDK Overview
Preparations
Android SDK
C SDK
C++ SDK
.NET(C#) SDK
Flutter SDK
Go SDK
iOS SDK
Java SDK
JavaScript SDK
Node.js SDK
PHP SDK
Python SDK
React Native SDK
Mini Program SDK
Error Codes
Harmony SDK
Endpoint SDK Quality Optimization
Security and Compliance
Data Disaster Recovery
Data Security
Cloud Access Management
FAQs
Popular Questions
General
Billing
Domain Name Compliance Issues
Bucket Configuration
Domain Names and CDN
Object Operations
Logging and Monitoring
Permission Management
Data Processing
Data Security
Pre-signed URL Issues
SDKs
Tools
APIs
Agreements
Service Level Agreement
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Bucket Tagging

PDF
Focus Mode
Font Size
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

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback