You can call this operation to add tags to a bucket or modify the tags of a bucket.

Usage notes

When you call the PutBucketTags operation, take note of the following items:

  • Only the owner of a bucket and authorized RAM users can configure tags for the bucket. If other users attempt to configure tags for the bucket, 403 Forbidden is returned with the error code AccessDenied.
  • A tag is a key-value pair. You can configure up to 20 tags for a bucket.
  • When you use PutBucketTags to add a tag to a bucket, the new tag overwrites the existing tag that has the same key.

Request structure

PUT /? tagging HTTP/1.1
Date: GMT Date
Content-Length: ContentLength
Authorization: SignatureValue
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
<? 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>

Request headers

A PutBucketTags request contains only common request headers. For more information, see Common request headers.

Request elements

Element Type Required Description
Tagging Container Yes The container used to store Tagset.

Child node: TagSet

Parent nodes: none

TagSet Container Yes The container used to store a set of Tags.

Child node: Tag

Parent node: Tagging

Tag Container Yes The container used to store the tag you want to add or modify.

Child nodes: Key and Value

Parent node: TagSet

Key String Yes The key of a tag.
  • A tag key is up to 64 bytes in length.
  • A tag key cannot start with http://, https://, or Aliyun.
  • A tag key must be UTF-8 encoded.
  • A tag key cannot be null.

Child node: none

Parent node: Tag

Value String No The value of a tag.
  • A tag value is up to 128 bytes in length.
  • A tag value must be UTF-8 encoded.
  • A tag value can be null.

Child node: none

Parent node: Tag

Response headers

The response to a PutBucketTags request contains only common response headers. For more information, see Common response headers.

Examples

  • Sample request
    PUT /? tagging
    Host: oss-example.oss-cn-hangzhou.aliyuncs.com
    Date: Tue, 20 Dec 2018 11:49:13 GMT
    Authorization: OSS qn6qrrqxo2oawuk53otf****:ceOEyZavKY4QcjoUWYSpYbJ3****
    <Tagging>
      <TagSet>
        <Tag>
          <Key>testa</Key>
          <Value>testv1</Value>
        </Tag>
        <Tag>
          <Key>testb</Key>
          <Value>testv2</Value>
        </Tag>
      </TagSet>
    </Tagging>
  • Sample response
    200 (OK)
    content-length: 0
    server: AliyunOSS
    x-oss-request-id: 5C1B138A109F4E405B2D****
    date: Thu, 20 Dec 2018 11:59:06 GMT
    x-oss-server-time: 148
    connection: keep-alive