This operation adds or updates the tag information for an object. An object tag is a key-value pair.
If you do not specify a version ID in a request, make sure that you have the PutObjectTagging permission. If you do specify a version ID in a request, make sure that you have the PutObjectTagging and PutObjectVersionTagging permissions. By default, only the object owner can perform this operation. The object owner can grant this permission to others by using a bucket or user policy.
Tags are added to the current version of an object by default. You can use the versionId parameter to add tags to any other version. If the version you are adding tags to is a delete marker, OBS returns 404 Not Found.
A tag key is case sensitive and must be unique. It cannot be left blank or exceed 128 characters. The following characters are not allowed: =*<>\,|/?!;
A tag value is case sensitive and can be left blank. It cannot exceed 255 characters. The following characters are not allowed: =*<>\,|?!;
PUT /objectname?tagging&versionId=versionid HTTP/1.1 Host: bucketname.obs.region.example.com Date: date Authorization: authorization string Content-MD5: md5 <?xml version="1.0" encoding="UTF-8"> <Tagging> <TagSet> <Tag> <Key>Key</Key> <Value>Value</Value> </Tag> </TagSet> </Tagging>
Table 1 describes the parameters in the request.
Table 2 describes the headers in the request.
Header |
Description |
Mandatory |
---|---|---|
Content-MD5 |
Base64-encoded 128-bit MD5 digest of the message according to RFC 1864. You can also configure the Content-SHA256 header whose value is the Base64-encoded SHA-256 digest of the message. Configure either Content-MD5 or Content-SHA256. Type: string Example: n58IG6hfM7vqI4K0vnWpog== |
Yes |
In this request body, you need to configure the object tags in XML. Table 3 describes the tag elements to be configured.
Header |
Description |
Mandatory |
---|---|---|
Tagging |
Root element for TagSet and Tag Type: container Parent: none |
Yes |
TagSet |
A collection for a set of tags. Type: container Parent: Tagging |
Yes |
Tag |
Information element of Tag Type: container Parent: TagSet |
Yes |
Key |
Tag name Type: string Parent: Tag |
Yes |
Value |
Tag value Type: string Parent: Tag |
Yes |
1 2 3 4 5 | HTTP/1.1 status_code x-obs-request-id: request id x-obs-id-2: id Content-Length: length Date: date |
This response uses common headers. For details, see Table 1.
This response contains no elements.
In addition to common error codes, this API also returns others. Table 4 lists the common errors and possible causes.
Error Code |
Description |
HTTP Status Code |
---|---|---|
InvalidTag |
The provided object tag was invalid. |
400 |
BadRequest |
The number of object tags exceeded the upper limit. |
400 |
MalformedXML |
The XML file was malformed. |
400 |
EntityTooLarge |
The request body was too long. |
400 |
AccessDenied |
No permission to configure object tags. |
403 |
MethodNotAllowed |
Method not allowed, because the corresponding feature was not enabled. |
405 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | PUT /objectname?tagging&versionId=G001018455096CE600005306000000DD HTTP/1.1 User-Agent: curl/7.29.0 Host: examplebucket.obs.region.example.com Accept: */* Date: Wed, 27 Jun 2018 13:22:50 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:Pf1ZyGvVYg2BzOjokZ/BAeR1mEQ= Content-MD5: MnAEvkfQIGnBpchOE2U6Og== Content-Length: 182 <Tagging xmlns="http://obs.region.example.com/doc/2015-06-30/"> <TagSet> <Tag> <Key>TagName1</Key> <Value>TageSetVaule1</Value> </Tag> </TagSet> </Tagging> |
1 2 3 4 5 | HTTP/1.1 200 OK Server: OBS x-obs-request-id: BF26000001643FEBA09B1ED46932CD07 x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSEZp87iEirC6DggPB5cN49pSvHBWClg Date: Wed, 27 Jun 2018 13:22:50 GMT |