Adding Object Tags
Functions
OBS allows you to use object tags to classify objects in a bucket. You can call this API to add or update tags for an existing object. For more information about object tags, see Adding Tags to an Object.
Constraints
- Object tags are now in open beta testing, and you can use them for free. Once the testing period is over, you will be billed for using object tags.
- To read or write object tags, you must be the object owner or have required permissions. Such permissions can be granted using bucket policies.
- During cross-region replication, tags of source objects are not copied.
- Tags cannot be added to files in parallel file systems.
- Currently, object tags cannot be used in IAM permissions or bucket policies.
- Tags cannot be added to files in parallel file systems.
- An object can have up to 10 tags.
- Constraints on the tag key and value:
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: ,/|<>=*\
Authorization Information
To call this API, you must be the object owner or have the permissions to add object tags. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.
- If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permissions:
- If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), you need to grant the obs:object:PutObjectTagging (versioning disabled) and obs:object:PutObjectVersionTagging (versioning enabled or suspended) permissions. For details, see Creating a Custom IAM Policy.
- If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), you need to grant the obs:object:putObjectTagging (versioning disabled) and obs:object:putObjectVersionTagging (versioning enabled or suspended) permissions, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.
Action
Access Level
Resource Type (*: Required)
Dependencies
obs:object:putObjectTagging (versioning disabled)
obs:object:putObjectVersionTagging (versioning enabled or suspended)
Tagging
object *
-
-
-
- g:RequestTag/<tag-key>
- g:TagKeys
- obs:EpochTime
- obs:SourceIp
- obs:TlsVersion
- obs:CustomDomain
- If you use bucket policies for authorization, you need to grant the obs:object:PutObjectTagging (versioning disabled) and obs:object:PutObjectVersionTagging (versioning enabled or suspended) permissions. For details, see Creating a Custom Bucket Policy.
Request Syntax
PUT /objectname?tagging&versionId=versionid HTTP/1.1
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> URI Parameters
Table 1 describes the parameters in the request.
| Parameter | Description | Mandatory |
|---|---|---|
| tagging | Indicates an object tagging request. Type: string | Yes |
| versionId | ID of the object version that the tag will be added to. The corresponding response header is x-obs-version-id. If the version is a delete marker, OBS returns 404 Not Found. Type: string | No |
Request Headers
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 |
Request Body
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 |
Response Syntax
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 |
Response Headers
This response uses common headers. For details, see Table 1.
Response Body
This response contains no elements.
Error Responses
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 |
Sample Request
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | PUT /objectname?tagging&versionId=G001018455096CE600005306000000DD HTTP/1.1 User-Agent: curl/7.29.0 Accept: */* Date: Wed, 27 Jun 2018 13:22:50 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:Pf1ZyGvVYg2BzOjokZ/BAeR1mEQ= Content-SHA256: ogX9qClMrVJUBiUSIKDFM0qO41jJM0I5SCN55/OtMyI= Content-MD5: MnAEvkfQIGnBpchOE2U6Og== Content-Length: 182 <TagSet> <Tag> <Key>TagName1</Key> <Value>TagSetValue1</Value> </Tag> </TagSet> </Tagging> |
Sample Response
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 |
Using SDKs to Call APIs
You are advised to use OBS SDKs to call APIs. SDKs encapsulate APIs to simplify development. You can call SDK API functions to access OBS without manually calculating signatures.
Helpful Links
- For more information about object tags, see Adding Tags to an Object.
- For details about the billing items involved in API operations, see Billing Items.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot