API | 操作名 | 操作描述 |
设置清单任务 | 设置存储桶的清单任务 | |
查询清单任务 | 查询存储桶的清单任务 | |
列出清单任务 | 列出存储桶的清单任务 | |
删除清单任务 | 删除存储桶的清单任务 |
CosResult BucketOp::PutBucketInventory(const PutBucketInventoryReq& req, PutBucketInventoryResp* resp);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::PutBucketInventoryReq req(bucket_name);qcloud_cos::PutBucketInventoryResp resp;// 设置清单任务req.SetId("list");COSBucketDestination destination;destination.SetFormat("CSV");destination.SetAccountId("100010974959");destination.SetBucket("qcs::cos:ap-guangzhou::loggtest-1234567890");destination.SetPrefix("/");destination.SetEncryption(true);OptionalFields fields;fields.SetIsSize(true);fields.SetIsLastModified(true);fields.SetIsStorageClass(true);fields.SetIsMultipartUploaded(true);fields.SetIsReplicationStatus(true);fields.SetIsEtag(true);Inventory inventory;inventory.SetIsEnable(true);inventory.SetIncludedObjectVersions("All");inventory.SetFilter("/");inventory.SetId(req.GetId());inventory.SetFrequency("Daily");inventory.SetCOSBucketDestination(destination);inventory.SetOptionalFields(fields);req.SetInventory(inventory);qcloud_cos::CosResult result = cos.PutBucketInventory(req, &resp);if (result.IsSucc()) {// 请求成功} else {// 请求失败,可以调用 CosResult 的成员函数输出错误信息,如 requestID 等}
参数 | 参数描述 | 类型 | 是否必填 |
req | PutBucketInventory 操作的请求 | PutBucketInventoryReq | 是 |
resp | PutBucketInventory 操作的响应 | PutBucketInventoryResp | 是 |
// 设置清单规则void SetInventory(Inventory& inventory);
// 清单配置参数class Inventory {void SetId(const std::string& id) // 设置清单的名称void SetIsEnable(bool is_enabled) // 清单是否启用void SetIncludedObjectVersions(const std::string& included_objectversions) // 是否在清单中包含对象版本:void SetFilter(const std::string& filter) // 筛选待分析对象(前缀)void SetCOSBucketDestination(const COSBucketDestination& destination) // 设置清单结果导出后存放的存储桶信息void SetOptionalFields(const OptionalFields& fields) // 设置清单结果中应包含的分析项目void SetFrequency(const std::string& frequency) // 设置清单任务的周期,支持 Daily 和 Weekly}// 清单结果中应包含的分析项目class OptionalFields {void SetIsSize(const bool size); // 设置是否需要文件大小void SetIsLastModified(const bool last_modified) // 设置是否需要文件修改时间void SetIsStorageClass(const bool storage_class) // 设置是否需要存储类型void SetIsMultipartUploaded(const bool ismultipart_uploaded) // 设置是否需要分块上传void SetIsReplicationStatus(const bool replication_status) // 设置是否需要跨区域复制状态}// 清单结果导出后存放的存储桶信息class COSBucketDestination {public:void SetFormat(const std::string& format) // 设置清单生成文件格式,目前支持 CSV 格式void SetAccountId(const std::string& accountId) // 存储桶的所有者 IDvoid SetBucket(const std::string& bucket) // 设置存储桶完整 IDvoid SetPrefix(const std::string& prefix) // 设置清单分析结果的存储桶名void SetEncryption(const bool encryption) // 设置清单结果是否加密
错误码 | 描述 | 状态码 |
InvalidArgument | 不合法的参数值 | HTTP 400 Bad Request |
TooManyConfigurations | 清单数量已经达到1000条的上限 | HTTP 400 Bad Request |
AccessDenied | 未授权的访问。您可能不具备访问该存储桶的权限 | HTTP 403 Forbidden |
CosResult CosAPI::GetBucketInventory(const GetBucketInventoryReq& request, GetBucketInventoryResp* response) {
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::GetBucketInventoryReq req(bucket_name);qcloud_cos::GetBucketInventoryResp resp;// 设置清单任务req.SetId("list");qcloud_cos::CosResult result = cos.GetBucketInventoryResp(req, &resp);if (result.IsSucc()) {// 请求成功,获取清单信息//const Inventory inventory = resp.GetInventory();//std::cout << "inventory isenabled:" << inventory.GetIsEnable() << std::endl;//std::cout << "inventory IncludedObjectVersions:" << inventory.GetIncludedObjectVersions() << std::endl;//std::cout << "inventory filter:" << inventory.GetFilter() << std::endl;//std::cout << "inventory id:" << inventory.GetId() << std::endl;//std::cout << "inventory Frequency:" << inventory.GetFrequency() << std::endl;//std:: cout << "===================================" << std::endl;//COSBucketDestination destination = inventory.GetCOSBucketDestination();//std::cout << "destination Format:" << destination.GetFormat() << std::endl;//std::cout << "destination AccountID:" << destination.GetAccountId() << std::endl;//std::cout << "destination Bucket:" << destination.GetBucket() << std::endl;//std::cout << "destination Encryption:" << destination.GetEncryption() << std::endl;//std:: cout << "===================================" << std::endl;////OptionalFields fields = inventory.GetOptionalFields();//std::cout << "fields Size:" << fields.GetIsSize() << std::endl;//std::cout << "fields LastModified:" << fields.GetIsLastModified() << std::endl;//std::cout << "fields StorageClass:" << fields.GetIsStorageClass() << std::endl;//std::cout << "fields Region:" << fields.GetIsMultipartUploaded() << std::endl;//std::cout << "fields ReplicationStatus:" << fields.GetIsReplicationStatus() << std::endl;//std::cout << "fields Tag:" << fields.GetIsETag() << std::endl;} else {// 请求失败,可以调用 CosResult 的成员函数输出错误信息,如 requestID 等}
参数 | 参数描述 | 类型 | 是否必填 |
req | GetBucketInventory 操作的请求 | GetBucketInventoryReq | 是 |
resp | GetBucketInventory 操作的响应 | GetBucketInventoryResp | 是 |
// 获取清单规则const Inventory& GetInventory() const;
CosResult CosAPI::ListBucketInventoryConfigurations(const ListBucketInventoryConfigurationsReq& request, ListBucketInventoryConfigurationsResp* response) {
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::ListBucketInventoryConfigurationsReq req(bucket_name);qcloud_cos::ListBucketInventoryConfigurationsResp resp;qcloud_cos::CosResult result = cos.ListBucketInventoryConfigurations(req, &resp);if (result.IsSucc()) {// 请求成功,获取清单信息// std::cout << "===================ListBucketInventoryConfigurations=====================" << std::endl;//// std::vector<Inventory> inventory_vec = resp.GetInventory();//// std::cout << resp.GetIsTruncated() << std::endl;// std::cout << resp.GetContinuationToken() << std::endl;// std::cout << resp.GetNextContinuationToken() << std::endl;//// std::vector<Inventory>::iterator itr = inventory_vec.begin();// for(; itr != inventory_vec.end(); ++itr) {//// std:: cout << "==============Inventory=============================" << std::endl;// std::cout << "inventory id:" << itr->GetId() << std::endl;// std::cout << "inventory isenabled:" << itr->GetIsEnable() << std::endl;// std::cout << "inventory IncludedObjectVersions:" << itr->GetIncludedObjectVersions() << std::endl;// std::cout << "inventory filter:" << itr->GetFilter() << std::endl;// std::cout << "inventory Frequency:" << itr->GetFrequency() << std::endl;// std:: cout << "==============GetCOSBucketDestination==================" << std::endl;// COSBucketDestination destination = itr->GetCOSBucketDestination();// std::cout << "destination Format:" << destination.GetFormat() << std::endl;// std::cout << "destination AccountID:" << destination.GetAccountId() << std::endl;// std::cout << "destination Bucket:" << destination.GetBucket() << std::endl;// std::cout << "destination Encryption:" << destination.GetEncryption() << std::endl;//// std:: cout << "===================OptionalFields======================" << std::endl;// OptionalFields fields = itr->GetOptionalFields();// std::cout << "fields Size:" << fields.GetIsSize() << std::endl;// std::cout << "fields LastModified:" << fields.GetIsLastModified() << std::endl;// std::cout << "fields StorageClass:" << fields.GetIsStorageClass() << std::endl;// std::cout << "fields Region:" << fields.GetIsMultipartUploaded() << std::endl;// std::cout << "fields ReplicationStatus:" << fields.GetIsReplicationStatus() << std::endl;// std::cout << "fields Tag:" << fields.GetIsETag() << std::endl;// }// std::cout << "===============ListBucketInventoryConfigurations end================" << std::endl;} else {// 请求失败,可以调用 CosResult 的成员函数输出错误信息,如 requestID 等}
参数 | 参数描述 | 类型 | 是否必填 |
req | ListBucketInventoryConfigurations 操作的请求 | ListBucketInventoryConfigurationsReq | 是 |
resp | ListBucketInventoryConfigurations 操作的响应 | ListBucketInventoryConfigurationsResp | 是 |
// 当 COS 响应体中 IsTruncated 为 true,且 NextContinuationToken 节点中存在参数值时,您可以将这个参数作为 continuation-token 参数值,以获取下一页的清单任务信息。void SetContinuationToken(const std::string continuation_token);
CosResult CosAPI::DeleteBucketInventory(const DeleteBucketInventoryReq& request, DeleteBucketInventoryResp* response);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::DeleteBucketInventoryReq req(bucket_name);qcloud_cos::DeleteBucketInventoryResp resp;qcloud_cos::CosResult result = cos.DeleteBucketInventory(req, &resp);if (result.IsSucc()) {// 请求成功} else {// 请求失败,可以调用 CosResult 的成员函数输出错误信息,如 requestID 等
参数 | 参数描述 | 类型 | 是否必填 |
req | DeletBucketInventory 操作的请求 | DeletBucketInventoryReq | 是 |
resp | DeletBucketInventory 操作的响应 | DeletBucketInventoryResp | 是 |
void SetId(const std::string id) // 设置要删除清单的 ID
本页内容是否解决了您的问题?