@@ -839,6 +839,73 @@ void GetObjectACL(qcloud_cos::CosAPI& cos, const std::string& bucket_name,
839839 << std::endl;
840840}
841841
842+ // 为已存在的 Object 设置标签(Tag)
843+ void PutObjectTagging (qcloud_cos::CosAPI& cos, const std::string& bucket_name,
844+ const std::string& object_name) {
845+ qcloud_cos::PutObjectTaggingReq req (bucket_name, object_name);
846+ qcloud_cos::PutObjectTaggingResp resp;
847+ std::vector<Tag> tagset;
848+ Tag tag1;
849+ tag1.SetKey (" age" );
850+ tag1.SetValue (" 19" );
851+
852+ Tag tag2;
853+ tag2.SetKey (" name" );
854+ tag2.SetValue (" xiaoming" );
855+
856+ Tag tag3;
857+ tag3.SetKey (" sex" );
858+ tag3.SetValue (" male" );
859+
860+ tagset.push_back (tag1);
861+ tagset.push_back (tag2);
862+ tagset.push_back (tag3);
863+ req.SetTagSet (tagset);
864+
865+ qcloud_cos::CosResult result = cos.PutObjectTagging (req, &resp);
866+ std::cout << " ===================PutBucketTagging====================="
867+ << std::endl;
868+ PrintResult (result, resp);
869+ std::cout
870+ << " ===================================================================="
871+ << std::endl;
872+ }
873+
874+ // 查询指定Object的标签
875+ void GetObjectTagging (qcloud_cos::CosAPI& cos, const std::string& bucket_name,
876+ const std::string& object_name) {
877+ qcloud_cos::GetObjectTaggingReq req (bucket_name, object_name);
878+ qcloud_cos::GetObjectTaggingResp resp;
879+
880+ qcloud_cos::CosResult result = cos.GetObjectTagging (req, &resp);
881+ std::cout << " ===================GetObjectTagging====================="
882+ << std::endl;
883+ std::vector<Tag> tagset = resp.GetTagSet ();
884+ for (std::vector<Tag>::iterator it = tagset.begin (); it != tagset.end ();
885+ ++it) {
886+ std::cout << it->GetKey () << " :" << it->GetValue () << std::endl;
887+ }
888+ PrintResult (result, resp);
889+ std::cout
890+ << " ===================================================================="
891+ << std::endl;
892+ }
893+
894+ // 删除指定Object的标签
895+ void DeleteObjectTagging (qcloud_cos::CosAPI& cos, const std::string& bucket_name,
896+ const std::string& object_name) {
897+ qcloud_cos::DeleteObjectTaggingReq req (bucket_name, object_name);
898+ qcloud_cos::DeleteObjectTaggingResp resp;
899+
900+ qcloud_cos::CosResult result = cos.DeleteObjectTagging (req, &resp);
901+ std::cout << " ===================DeleteObjectTagging====================="
902+ << std::endl;
903+ PrintResult (result, resp);
904+ std::cout
905+ << " ===================================================================="
906+ << std::endl;
907+ }
908+
842909void PutObjectCopy (qcloud_cos::CosAPI& cos, const std::string& bucket_name,
843910 const std::string& object_name, const std::string& source) {
844911 qcloud_cos::PutObjectCopyReq req (bucket_name, object_name);
0 commit comments