获取对象标签
本文介绍如何获取对象标签(Object Tagging)。
对象标签使用一组键值对(Key-Value)来标记对象。对象标签的详情请参考开发指南的对象标签。
以下代码用于获取对象标签信息:
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;
int main(void)
{
/* 初始化OSS账号信息 */
std::string AccessKeyId = "yourAccessKeyId";
std::string AccessKeySecret = "yourAccessKeySecret";
std::string Endpoint = "yourEndpoint";
std::string BucketName = "yourBucketName";
std::string ObjectName = "yourObjectName";
/* 初始化网络等资源 */
InitializeSdk();
ClientConfiguration conf;
OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);
std::shared_ptr<std::iostream> content = std::make_shared<std::stringstream>();
*content << "test cpp sdk";
PutObjectRequest request(BucketName, ObjectName, content);
/* 上传文件 */
auto outcome = client.PutObject(request);
/* 设置对象标签 */
Tagging tagging;
tagging.addTag(Tag("key1", "value1"));
tagging.addTag(Tag("key2", "value2"));
auto putTaggingOutcome = client.SetObjectTagging(SetObjectTaggingRequest(BucketName, ObjectName, tagging));
/* 获取对象标签 */
getTaggingOutcome = client.GetObjectTagging(GetObjectTaggingRequest(BucketName, key));
if (!getTaggingOutcome.isSuccess()) {
/* 异常处理 */
std::cout << "getTaggingOutcome fail" <<
",code:" << getTaggingOutcome.error().Code() <<
",message:" << getTaggingOutcome.error().Message() <<
",requestId:" << getTaggingOutcome.error().RequestId() << std::endl;
ShutdownSdk();
return -1;
}
else {
auto taglist = getTaggingOutcome.result().Tagging();
for (const auto& tag : taglist)
{
std::cout <<"GetObjectTagging success, Key:"
<< tag.Key() << "; Value:" << tag.Value() << std::endl;
}
}
/* 释放网络等资源 */
ShutdownSdk();
return 0;
}
获取对象标签详情请参考GetObjectTagging。
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
评论