All Products
Search
Document Center

Object Storage Service:put-object-tagging

Last Updated:Sep 25, 2024

The command put-object-tagging is used to add tags to an object or edit the tags added to the object.

Usage notes

  • By default, an Alibaba Cloud account has the permissions to add or edit the tags of an object. Adding and editing tags as a RAM user or by using Security Token Service (STS) require oss:PutObjectTagging permissions. For more information, see Attach a custom policy to a RAM user.

  • Each tag added to an object is a key-value pair. You can add up to 10 tags to an object. The tags added to an object must have unique tag keys. A tag key can be up to 128 characters in length. A tag value can be up to 256 characters in length. Tag keys and values are case-sensitive. The key and value of a tag can contain letters, digits, spaces, and the following special characters: +-=._:/.

  • Editing tags of an object does not update the Last-Modified parameter of the object.

Command syntax

ossutil api put-object-tagging --bucket value --key value --tagging value [flags]

Parameter

Type

Description

--bucket

string

Bucket name.

--key

string

Full path of the object.

--tagging

string

Tags.

--version-id

string

Version ID of the object.

Note

The put-object-tagging command corresponds to the PutObjectTagging operation. For more information about the parameters in the PutObjectTagging operation, see PutObjectTagging.

--tagging

The --tagging configuration option supports both XML and JSON formats. If the value of the option contains the 'file://' prefix, configuration parameters are read from the specified file.

  • XML format:

    <Tagging>
      <TagSet>
        <Tag>
          <Key>string</Key>
          <Value>string</Value>
        </Tag>
        ...
      </TagSet>
    </Tagging>
  • JSON format:

    {
      "TagSet": {
        "Tag": [
          {
            "Key": "string",
            "Value": "string"
          },
          ...
        ]
      }
    }
Note

For more information about supported global command-line options, see Command-line options.

Examples

Add or edit tags for exampleobject.

  • Create a configuration file named tagging.xml and add the following code:

    <?xml version="1.0" encoding="UTF-8"?>
    <Tagging>
      <TagSet>
        <Tag>
          <Key>key1</Key>
          <Value>value1</Value>
        </Tag>
        <Tag>
          <Key>key2</Key>
          <Value>value2</Value>
        </Tag>
      </TagSet>
    </Tagging>

    Sample command:

    ossutil api put-object-tagging --bucket examplebucket --key exampleobject --tagging file://tagging.xml
  • Create a configuration file named tagging.json and add the following code:

    {
      "TagSet": {
        "Tag": [
          {
            "Key": "key1",
            "Value": "value1"
          },
          {
            "Key": "key2",
            "Value": "value2"
          }
        ]
      }
    }

    Sample command:

    ossutil api put-object-tagging --bucket examplebucket --key exampleobject --tagging file://tagging.json
  • Configure parameters in the following command in the JSON format:

    ossutil api put-object-tagging --bucket examplebucket --key exampleobject --tagging "{\"TagSet\":{\"Tag\":[{\"Key\":\"key1\",\"Value\":\"value1\"},{\"Key\":\"key2\",\"Value\":\"value2\"}]}}"