All Products
Search
Document Center

Object Storage Service:PutObjectTagging

Last Updated:Feb 18, 2025

Use the PutObjectTagging operation to assign or update an object's tagging information. Object tagging employs key-value pairs for identification.

Notes

  • You can attach up to 10 tags per object, each with a unique tag key.

  • Tag keys can be up to 128 characters long, and tag values can be up to 256 characters long.

  • Tag keys and values are case-sensitive.

  • Tags may include letters, digits, spaces, and special characters such as:

    +‑=._:/

    Perform URL encoding on tag keys and values containing special characters in the HTTP header.

  • Changing an object's tags does not update its Last-Modified timestamp.

For additional details on object tagging, see object tagging.

Versioning

By default, invoking the PutObjectTagging operation sets tags for the current version of an object. To tag a specific version or update its tags, include the version ID in your request. If the specified version is a delete marker, OSS returns a 404 Not Found error.

Request syntax

PUT /objectname?tagging
Content‐Length: 114
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
Date: Mon, 18 Mar 2019 08:25:17 GMT
Authorization: SignatureValue
<Tagging>
  <TagSet>
    <Tag>
      <Key>Key</Key>
      <Value>Value</Value>
    </Tag>
  </TagSet>
</Tagging>            

Request elements

Name

Type

Required

Example

Description

Tagging

Container

Yes

N/A

The container that stores the returned tag sets.

Child nodes: TagSet

TagSet

Container

Yes

N/A

The container that stores the returned tag sets.

Parent nodes: Tagging

Child nodes: Tag

Tag

Container

No

N/A

The container that stores the returned tag sets.

Parent nodes: TagSet

Child nodes: Key and Value

Key

String

No

a

The tag key.

Parent nodes: Tag

Child nodes: none

Value

String

No

1

The tag value.

Parent nodes: Tag

Child nodes: none

This operation also includes common request headers. For further details, see common request headers.

Examples

  • Unversioned

    In this example, the object 'objectname' in the unversioned bucket 'bucketname' is tagged with {a:1} and {b:2} using a PutObjectTagging request. The operation returns HTTP status code 200 (OK) upon success.

    Query example

    PUT /objectname?tagging
    Content‐Length: 114
    Host: BucketName.oss-cn-hangzhou.aliyuncs.com
    Date: Mon, 18 Mar 2019 08:25:17 GMT
    Authorization: OSS qn6q**************:77Dv****************
    <Tagging>
      <TagSet>
        <Tag>
          <Key>a</Key>
          <Value>1</Value>
        </Tag>
        <Tag>
          <Key>b</Key>
          <Value>2</Value>
        </Tag>
      </TagSet>
    </Tagging>

    Sample success response

    200 (OK)
    content‐length: 0
    server: AliyunOSS
    connection: keep-alive
    x‐oss‐request‐id: 5C8F55ED461FB4A64C00****
    date: Mon, 18 Mar 2019 08:25:17 GMT
  • Versioned

    Here, the object 'objectname' in the versioned bucket 'bucketname' is tagged with {age:18} for a specified version. The operation returns HTTP status code 200 (OK) upon success.

    Query example

    PUT /objectname?tagging&versionId=CAEQExiBgID.jImWlxciIDQ2ZjgwODIyNDk5MTRhNzBiYmQwYTZkMTYzZjM0****
    Content-Length: 90
    Host: BucketName.oss-cn-hangzhou.aliyuncs.com
    Date: Wed, 24 Jun 2020 08:58:15 GMT
    Authorization: OSS qn6q**************:77Dv****************
    <Tagging>
      <TagSet>
        <Tag>
          <Key>age</Key>
          <Value>18</Value>
        </Tag>
      </TagSet>
    </Tagging>

    Sample success response

    200 (OK)
    content-length: 0
    server: AliyunOSS
    connection: keep-alive
    x-oss-request-id: 5EF315A7FBD3EC3232B4****
    date: Wed, 24 Jun 2020 08:58:15 GMT
    x-oss-version-id: CAEQExiBgID.jImWlxciIDQ2ZjgwODIyNDk5MTRhNzBiYmQwYTZkMTYzZjM0****

SDK

Below are examples of using the PutObjectTagging operation in various SDKs:

Command line tool ossutil

For the ossutil command corresponding to the PutObjectTagging operation, refer to put-object-tagging.

Error codes

Error code

HTTP status code

Description

FileAlreadyExists

409

If the hierarchical namespace feature is enabled for a bucket, this error is returned when you attempt to configure or update tags for an object that is a directory within the bucket.