use of com.qcloud.cos.model.Tag.Tag in project cos-java-sdk-v5 by tencentyun.
the class ObjectTaggingDemo method SetGetDelObjectTaggingDemo.
public static void SetGetDelObjectTaggingDemo() {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("COS_SECRET_ID", "COS_SECRET_KEY");
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
String key = "aaa/bbb.txt";
cosclient.putObject(bucketName, key, "data");
List<Tag> tags = new LinkedList<>();
tags.add(new Tag("key", "value"));
tags.add(new Tag("key-1", "value-1"));
ObjectTagging objectTagging = new ObjectTagging(tags);
SetObjectTaggingRequest setObjectTaggingRequest = new SetObjectTaggingRequest(bucketName, key, objectTagging);
cosclient.setObjectTagging(setObjectTaggingRequest);
GetObjectTaggingResult getObjectTaggingResult = cosclient.getObjectTagging(new GetObjectTaggingRequest(bucketName, key));
List<Tag> resultTagSet = getObjectTaggingResult.getTagSet();
cosclient.deleteObjectTagging(new DeleteObjectTaggingRequest(bucketName, key));
GetObjectTaggingResult getObjectTaggingResultSecond = cosclient.getObjectTagging(new GetObjectTaggingRequest(bucketName, key));
List<Tag> resultTagSetSecond = getObjectTaggingResultSecond.getTagSet();
}
use of com.qcloud.cos.model.Tag.Tag in project cos-java-sdk-v5 by tencentyun.
the class ObjectTaggingXmlFactory method convertToXmlByteArray.
public byte[] convertToXmlByteArray(ObjectTagging tagging) {
XmlWriter writer = new XmlWriter();
writer.start("Tagging").start("TagSet");
for (Tag tag : tagging.getTagSet()) {
writer.start("Tag");
writer.start("Key").value(tag.getKey()).end();
writer.start("Value").value(tag.getValue()).end();
// </Tag>
writer.end();
}
// </TagSet>
writer.end();
// </Tagging>
writer.end();
return writer.getBytes();
}
use of com.qcloud.cos.model.Tag.Tag in project cos-java-sdk-v5 by tencentyun.
the class ObjecTaggingTest method testSetGetDelObjectTagging.
@Test
public void testSetGetDelObjectTagging() throws IOException {
String key = "tagging.txt";
try {
cosclient.putObject(bucket, key, "data");
List<Tag> tags = new LinkedList<>();
tags.add(new Tag("key", "value"));
tags.add(new Tag("key-1", "value-1"));
ObjectTagging objectTagging = new ObjectTagging(tags);
SetObjectTaggingRequest setObjectTaggingRequest = new SetObjectTaggingRequest(bucket, key, objectTagging);
cosclient.setObjectTagging(setObjectTaggingRequest);
GetObjectTaggingResult getObjectTaggingResult = cosclient.getObjectTagging(new GetObjectTaggingRequest(bucket, key));
assertEquals(getObjectTaggingResult.getTagSet(), tags);
;
cosclient.deleteObjectTagging(new DeleteObjectTaggingRequest(bucket, key));
GetObjectTaggingResult getObjectTaggingResultSecond = cosclient.getObjectTagging(new GetObjectTaggingRequest(bucket, key));
List<Tag> resultTagSetSecond = getObjectTaggingResultSecond.getTagSet();
assertEquals(resultTagSetSecond.size(), 0);
} finally {
cosclient.deleteObject(bucket, key);
}
}
Aggregations