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

Object Tagging

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2024-02-02 16:24:05

Overview

This document provides an overview of APIs and SDK code samples related to object tagging.
API
Operation
Description
Tagging an object
Tags an uploaded object.
Querying object tags
Queries all tags of an object.
Deleting object tags
Deletes all tags of an object.

Tagging an Object

Description

This API is used to tag an object.

Method prototype

public SetObjectTaggingResult setObjectTagging(SetObjectTaggingRequest setObjectTaggingRequest);

Sample 1. Tagging an uploaded object

String bucketName = "examplebucket-1250000000";
String key = "exampletkey";
List<Tag> tags = new LinkedList<>();
tags.add(new Tag("tag1", "value1"));
tags.add(new Tag("tag2", "value2"));
ObjectTagging objectTagging = new ObjectTagging(tags);
SetObjectTaggingRequest setObjectTaggingRequest = new SetObjectTaggingRequest(bucketName, key, objectTagging);
cosclient.setObjectTagging(setObjectTaggingRequest);

Sample 2. Tagging an object when it is uploaded

String bucketName = "examplebucket-1250000000";
String key = "testfiles/testTagging.txt";
InputStream is = new ByteArrayInputStream(new byte[]{'d', 'a', 't', 'a'});
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setHeader("x-cos-tagging", "tag1=value1&tag2=value2");
cosclient.putObject(bucketName, key, is, objectMetadata);

Parameter description

Parameter
Description
Type
setObjectTaggingRequest
Object tagging request
SetObjectTaggingRequest
The request members are described as follows:
Request Member
Setting Method
Description
Type
bucketName
Via a constructor or the set method
Bucket of the object to tag in the format of BucketName-APPID. For details, see Naming Conventions
String
Key
Via a constructor or the set method
Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key
String
objectTagging
Via a constructor or the set method
Object tagging
ObjectTagging
ObjectTagging member description:
Parameter
Description
Type
tagSet
Tags to add to the object
List<Tag>
Tag member description:
Parameter
Description
Type
key
Tag key
String
value
Tag value
String

Response description

Success: No value is returned.
Failure: If an error (such as authentication failure) occurs, the CosClientException or CosServiceException exception will be thrown. For more information, please see Troubleshooting.

Querying Object Tags

Description

This API is used to query the existing tags of a specified object.

Method prototype

public GetObjectTaggingResult getObjectTagging(GetObjectTaggingRequest getObjectTaggingRequest);

Sample request

String bucketName = "exampletbucket-1250000000";
String key = "exampletkey";
GetObjectTaggingRequest getObjectTaggingRequest = new GetObjectTaggingRequest(bucketName, key);
GetObjectTaggingResult getObjectTaggingResult = cosclient.getObjectTagging(getObjectTaggingRequest);
List<Tag> resultTagSet = getObjectTaggingResult.getTagSet();
System.out.println(resultTagSet.toString());

Parameter description

Parameter
Description
Type
getObjectTaggingRequest
Request to query the tags of an object
GetObjectTaggingRequest
The request members are described as follows:
Request Member
Setting Method
Description
Type
bucketName
Via a constructor or the set method
Bucket of the object to tag in the format of BucketName-APPID. For details, see Naming Conventions
String
Key
Via a constructor or the set method
Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key
String

Response description

Success: GetObjectTaggingResult is returned, which includes the tag information of the object.
Failure: If an error (such as authentication failure) occurs, the CosClientException or CosServiceException exception will be thrown. For more information, please see Troubleshooting.

Deleting Object Tags

Description

This API is used to delete the existing tags of a specified object.

Method prototype

public DeleteObjectTaggingResult deleteObjectTagging(DeleteObjectTaggingRequest deleteObjectTaggingRequest);

Sample request

String bucketName = "examplebucket-1250000000";
String key = "exampleobject";
DeleteObjectTaggingRequest deleteObjectTaggingRequest = new DeleteObjectTaggingRequest(bucketName, key);
cosclient.deleteObjectTagging(deleteObjectTaggingRequest);

Parameter description

Parameter
Description
Type
deleteObjectTaggingRequest
Request to delete the tags of an object
DeleteObjectTaggingRequest
The request members are described as follows:
Request Member
Setting Method
Description
Type
bucketName
Via a constructor or the set method
Bucket of the object to tag in the format of BucketName-APPID. For details, see Naming Conventions
String
Key
Via a constructor or the set method
Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key
String

Response description

Success: No value is returned.
Failure: If an error (such as authentication failure) occurs, the CosClientException or CosServiceException exception will be thrown. For more information, please see Troubleshooting.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan