Feature Overview
This API (PUT Object tagging) is used to set tags on an existing object. It can help you group and manage existing object resources by adding key-value pairs as object tags. For more information, please see Object Tagging Overview.
If a sub-account needs to call this API (
PUT Object tagging), ensure that the root account has authorized it to do so.Note:
Currently, you can set up to 10 different tags on one object.
If an object tag already exists, calling this interface will overwrite the existing tag.
Versioning
If your bucket has versioning enabled and you need to add tags to a specific version (not null) of an object, you can include the versionId parameter in the request. The object tags will be added to the specified object version. If you attempt to add tags to an object with a null version, it will not take effect, and the tags will be added to the latest object version instead.
Requests
Sample Request
PUT /<ObjectKey>?tagging&VersionId=VersionId HTTP 1.1Host:<BucketName-APPID>.cos.<Region>.myqcloud.comDate: GMT DateAuthorization: Auth String
Note:
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com, where <BucketName-APPID> is the bucket name with the APPID suffix, such as examplebucket-1250000000. You can refer to the Bucket Overview > Basic Information and Bucket Overview > Bucket Naming Convention documentation. <Region> represents the available regions for COS, which can be found in the Regions and Access Domain Names documentation.
Authorization: Auth String (For more information, see Request Signature.)
Request Parameters
Name | Description | Type | Required |
versionId | Version ID of the object (if versioning is enabled). If this parameter is not specified, tags will be added to the latest version of the object. | string | Not required |
Request Header
Request Body
You need to set the following tag set in the request body:
<?xml version="1.0" encoding="UTF-8" ?><Tagging><TagSet><Tag><Key>string</Key><Value>string</Value></Tag></TagSet></Tagging>
The nodes are described as follows:
Node Name (Keyword) | Parent Node | Description | Type | Required |
Tagging | - | Tagging configuration | Container | Required |
TagSet | Tagging | Tagging configuration | Container | Required |
Tag | Tagging.TagSet | A set of tags. Up to 10 tags are supported. | Containers | Required |
Key | Tagging.TagSet.Tag | Tag key: Up to 128 characters in length. Supports letters, digits, spaces, plus signs, hyphens, underscores, equal signs, periods, colons, and slashes. | String | Required |
Value | Tagging.TagSet.Tag | Tag value: Up to 256 characters in length. Supports letters, digits, spaces, plus signs, hyphens, underscores, equal signs, periods, colons, and slashes. | String | Required |
Response
Response Header
Response Body
The response body is empty.
Error Codes
Examples
Requests
The following request writes two tags,
{age:18} and {name:xiaoming}, to the object exampleobject.txt in the bucket examplebucket-1250000000. COS successfully configures the tags and returns a 200 success response.PUT /exampleobject.txt?tagging HTTP/1.1User-Agent: curl/7.29.0Accept: */*Host: examplebucket-1250000000.cos.ap-beijing.myqcloud.comAuthorization: Auth StringContent-Length: 127Content-MD5:MD5 StringContent-Type: application/xml<Tagging><TagSet><Tag><Key>age</Key><Value>18</Value></Tag><Tag><Key>name</Key><Value>xiaoming</Value></Tag></TagSet></Tagging>
Response
HTTP/1.1 200 OKContent-Type: application/xmlContent-Length: 0Connection: keep-aliveDate: Fri, 19 Jan 2020 11:40:22 GMTServer: tencent-cosx-cos-request-id: NWE2MWQ5MjZfMTBhYzM1MGFfMTA5ODVfMTVj****