Object Tag
Updated at:2025-11-03
Set object tags
Currently, BOS supports two ways to set object tagging. The first is to use the Canned method. When using putObjectTagging, set the tag by configuring the cannedTag field of PutObjectTaggingRequest. The second way is to construct an object tag json. The Java SDK has encapsulated both methods. For detailed information, please refer to Object Tags. The specific demos are as follows
- Set object tags via the Canned method
Java
1String objectTagString = "key1=value1&key2=values2";
2PutObjectTaggingRequest request = new PutObjectTaggingRequest(bucketName,ObjectName,objectTagString);
3client.putObjectTagging(request);
- Set object tagging by constructing a structure
Java
1List<ObjectTag> objectTags = new ArrayList<>();
2Map<String ,String> map = new HashMap<>();
3map.put("k1","v1");
4map.put("k2","v2");
5objectTags.add(ObjectTag.builder().tagInfo(map).build());
6this.client.putObjectTagging(bucketName,objectName,objectTags);
The fields of the ObjectTag structure are as follows:
| Parameters | Description |
|---|---|
| tagInfo | Hash map, tag information |
| +key | String, tag key |
| +value | String, tag value |
View object tags
The following code can be used to check the object permissions:
Java
1GetObjectTaggingResponse response = this.client.getObjectTagging(bucketName,objectName);
2System.out.println(response.toString());
Delete object tags
The following code can be used to delete the object permissions:
Java
1DeleteObjectTaggingRequest request = new DeleteObjectTaggingRequest("yourBucketName","objectKey");
2this.client.deleteObjectTagging(request);
