Object标签管理
更新时间:2024-04-08
Object Tagging
BOS目前支持直接设置object标签, 以及上传object时指定object标签
设置文件的标签
PutObjectTaggingRequest req("bucket", "object");
PutObjectTaggingResponse rsp;
req.add_object_tagging("key", "valaue");
req.add_object_tagging("key1", "valaue1");
int ret = client()->put_object_tagging(req, &rsp);
if (ret) {
LOGF(WARN, "client err: %d", ret);
}
if (rsp.is_fail()) {
LOGF(WARN,
"put_ns_object: [status_code = %d], [message = %s], [requestid = %s]",
rsp.status_code(),
rsp.error().message().c_str(),
rsp.error().request_id().c_str());
}
上传文件, 同时设置标签
PutObjectRequest req("bucket", "object", "data");
PutObjectResponse rsp;
#设置标签
req.add_object_tagging("key", "valaue");
req.add_object_tagging("key1", "value1");
int ret = client()->put_object(req, &rsp);
if (ret) {
LOGF(WARN, "client err: %d", ret);
}
if (rsp.is_fail()) {
LOGF(WARN,
"put_ns_object: [status_code = %d], [message = %s], [requestid = %s]",
rsp.status_code(),
rsp.error().message().c_str(),
rsp.error().request_id().c_str());
}
获取文件的标签
GetObjectTaggingRequest req("bucket", "object");
GetObjectTaggingResponse rsp;
int ret = client()->get_object_tagging(req, &rsp);
if (ret) {
LOGF(WARN, "client err: %d", ret);
}
if (rsp.is_fail()) {
LOGF(WARN,
"put_ns_object: [status_code = %d], [message = %s], [requestid = %s]",
rsp.status_code(),
rsp.error().message().c_str(),
rsp.error().request_id().c_str());
}
// 遍历获取到的标签
for (const auto& tag : rsp.tag_set()) {
LOGF(INFO, "key: %s, value: %s", tag.key.c_str(), tag.value.c_str());
}