You can use the object tagging function to classify OSS objects. You can set lifecycle rules for objects with the same tag in batches.

Note The object tagging function is in the beta testing phase. You can open a ticket to apply for the trial of this function.

The object tagging function uses a key-value pair to tag an object. You can add a tag to an object when uploading the object or add a tag to an existing object.

  • You can add up to 10 tags with different keys to an object.
  • The maximum length of a key and a value is 128 bytes and 256 bytes individually.
  • The key and value are both case-sensitive.
  • A tag can contain letters, numbers, spaces, and the following symbols: + ‑ = . _ : /
  • Only the owner of a bucket and authorized users can read and write the tags of an object in the bucket. The read and write permissions on the tags of an object are not restricted by the ACL for the object.
  • When you copy an object to another region, the tags of the object is also copied to the region.

Application scenarios

The object tagging function is not limited by folders. You can select all objects with the same tag in a bucket and set lifecycle rules for the objects in batches. For example, you can add tags to objects that are generated periodically and do not need to be stored for a long period, and then set a lifecycle rule for the objects with the tags to delete them periodically.

Usage

  • APIs that may be used by the object tagging function are listed as follows:
    • PutObjectTagging: Adds a tag to an object. If the target object already has a tag, the original tag is overwritten by the new tag.
    • GetObjectTagging: Reads the tags of an object.
    • DeleteObjectTagging: Deletes the tags of an object.
    • PutObject: When using PutObject to upload an object, you can specify the x‑oss‑tagging request header to add tags to the object.
    • InitiateMultipartUpload: When initiating a multipart upload task, you can specify the x‑oss‑tagging request header to add tags to the object.
    • CopyObject: When copying an object, you can specify the x‑oss‑tagging‑directive request header to determine whether to copy the tags of the original object and specify the x‑oss‑tagging request header to specify the tags of the target object.
    • GetObject: If the user has the permission to read the tags of the target object, the x‑oss‑tagging‑count header is included in the response to the GetObject request to indicate the number of tags added to the target object.
    • HeadObject: If the user has the permission to read the tags of the target object, the x‑oss‑tagging‑count header is included in the response to the HeadObject request to indicate the number of tags added to the target object.
  • Required permission
    The permissions required by APIs related to the object tagging function are listed as follows:
    • GetObjectTagging: Requires the permission to obtain the tags of the object. With this permission, you can view the tags added to an object.
    • PutObjectTagging: Requires the permission to configure the tags of the object. With this permission, you can configure tags for an object.
    • DeleteObjectTagging: Requires the permission to delete the tags of the object. With this permission, you can delete the tags of an object.

Object tagging and lifecycle rule management

When setting a lifecycle rule, you can specify the condition of the rule so that it applies to objects with a specified prefix or a specified tag. You can also set the prefix and tag as the condition of a rule at the same time.
  • If you set a specified tag as the condition of a lifecycle rule, the rule applies to an object only when the key and value in the tag of the object both match the specified tag.
  • If you specify a prefix and multiple tags as the condition of a lifecycle rule, the rule applies to an object only when the prefix and tags of the object match the prefix and all tags specified in the rule.
Example:
<LifecycleConfiguration>
<Rule>
<ID>r1</ID>
<Prefix>rule1</Prefix>
<Tag><Key>xx</Key><Value>1</Value></Tag>
<Tag><Key>yy</Key><Value>2</Value></Tag>
<Status>Enabled</Status>
<Expiration>
<Days>30</Days>
</Expiration>
</Rule>
<Rule>
<ID>r2</ID>
<Prefix>rule2</Prefix>
<Tag><Key>xx</Key><Value>1</Value></Tag>
<Status>Enabled</Status>
<Transition>
<Days>60</Days>
<StorageClass>Archive</StorageClass>
</Transition>
</Rule>
</LifecycleConfiguration>

If you set the preceding lifecycle rule:

  • Objects with the rule1 prefix and "xx=1" and "yy=2" tags are deleted after 30 days.
  • The storage class of objects with the rule2 prefix and "xx=1" tag is converted to Archive after 60 days.
Note For more information, see Manage lifecycle rules.