This document provides an overview of APIs and SDK code samples related to object tagging.
API | Operation | Description |
---|---|---|
PUT Object tagging | Tagging an object | Tags an uploaded object. |
GET Object tagging | Querying object tags | Queries all tags of an object. |
DELETE Object tagging | Deleting object tags | Deletes all tags of an object. |
This API is used to tag an object.
public SetObjectTaggingResult setObjectTagging(SetObjectTaggingRequest setObjectTaggingRequest);
String bucketName = "examplebucket-1250000000";
String key = "exampletkey";
List<Tag> tags = new LinkedList<>();
tags.add(new Tag("tag1", "value1"));
tags.add(new Tag("tag2", "value2"));
ObjectTagging objectTagging = new ObjectTagging(tags);
SetObjectTaggingRequest setObjectTaggingRequest = new SetObjectTaggingRequest(bucketName, key, objectTagging);
cosclient.setObjectTagging(setObjectTaggingRequest);
String bucketName = "examplebucket-1250000000";
String key = "testfiles/testTagging.txt";
InputStream is = new ByteArrayInputStream(new byte[]{'d', 'a', 't', 'a'});
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setHeader("x-cos-tagging", "tag1=value1&tag2=value2");
cosclient.putObject(bucketName, key, is, objectMetadata);
Parameter | Description | Type |
---|---|---|
setObjectTaggingRequest | Object tagging request | SetObjectTaggingRequest |
The request members are described as follows:
Request Member | Setting Method | Description | Type |
---|---|---|---|
bucketName | Via a constructor or the set method | Bucket of the object to tag in the format of BucketName-APPID . For details, see Naming Conventions |
String |
Key | Via a constructor or the set method | Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key | String |
objectTagging | Via a constructor or the set method | Object tagging | ObjectTagging |
ObjectTagging member description:
Parameter | Description | Type |
---|---|---|
tagSet | Tags to add to the object | List&dxlt;Tag> |
Tag member description:
Parameter | Description | Type |
---|---|---|
key | Tag key | String |
value | Tag value | String |
This API is used to query the existing tags of a specified object.
public GetObjectTaggingResult getObjectTagging(GetObjectTaggingRequest getObjectTaggingRequest);
String bucketName = "exampletbucket-1250000000";
String key = "exampletkey";
GetObjectTaggingRequest getObjectTaggingRequest = new GetObjectTaggingRequest(bucketName, key);
GetObjectTaggingResult getObjectTaggingResult = cosclient.getObjectTagging(getObjectTaggingRequest);
List<Tag> resultTagSet = getObjectTaggingResult.getTagSet();
System.out.println(resultTagSet.toString());
Parameter | Description | Type |
---|---|---|
getObjectTaggingRequest | Request to query the tags of an object | GetObjectTaggingRequest |
The request members are described as follows:
Request Member | Setting Method | Description | Type |
---|---|---|---|
bucketName | Via a constructor or the set method | Bucket of the object to tag in the format of BucketName-APPID . For details, see Naming Conventions |
String |
Key | Via a constructor or the set method | Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key | String |
This API is used to delete the existing tags of a specified object.
public DeleteObjectTaggingResult deleteObjectTagging(DeleteObjectTaggingRequest deleteObjectTaggingRequest);
String bucketName = "examplebucket-1250000000";
String key = "exampleobject";
DeleteObjectTaggingRequest deleteObjectTaggingRequest = new DeleteObjectTaggingRequest(bucketName, key);
cosclient.deleteObjectTagging(deleteObjectTaggingRequest);
Parameter | Description | Type |
---|---|---|
deleteObjectTaggingRequest | Request to delete the tags of an object | DeleteObjectTaggingRequest |
The request members are described as follows:
Request Member | Setting Method | Description | Type |
---|---|---|---|
bucketName | Via a constructor or the set method | Bucket of the object to tag in the format of BucketName-APPID . For details, see Naming Conventions |
String |
Key | Via a constructor or the set method | Key of the object to tag. An object key uniquely identifies an object in a bucket. For more information, see Object Overview > Object Key | String |
Apakah halaman ini membantu?