API | 操作名 | 操作描述 |
设置生命周期 | 设置存储桶生命周期管理的配置 | |
查询生命周期 | 查询存储桶生命周期管理的配置 | |
删除生命周期 | 删除存储桶生命周期管理的配置 |
CosResult CosAPI::PutBucketLifecycle(const PutBucketLifecycleReq& request, PutBucketLifecycleResp* response)
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::PutBucketLifecycleReq req(bucket_name);qcloud_cos::PutBucketLifecycleResp resp;qcloud_cos::LifecycleRule rule;rule.SetIsEnable(true); // 指明规则是否启用,枚举值:Enabled,Disabledrule.SetId("lifecycle_rule00"); // 用于唯一地标识规则,长度不能超过255个字符qcloud_cos::LifecycleFilter filter;filter.SetPrefix("test");rule.SetFilter(filter); // 指定规则所适用的前缀。匹配前缀的对象受该规则影响,Prefix最多只能有一个qcloud_cos::LifecycleTransition transition; // 规则转换属性transition.SetDays(30);transition.SetStorageClass("Standard_IA");rule.AddTransition(transition);req.AddRule(rule);qcloud_cos::CosResult result = cos.GetBucketWebsite(req, &resp);if (result.IsSucc()) {// 请求成功} else {// 请求失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等}
参数 | 参数描述 | 类型 | 是否必填 |
req | PutBucketLifecycle 操作的请求 | PutBucketLifecycleReq | 是 |
resp | PutBucketLifecycle 操作的响应 | PutBucketLifecycleResp | 是 |
void AddRule(const LifecycleRule& rule);void SetRule(const std::vector<LifecycleRule>& rules);
include/cos_defines.h
CosResult CosAPI::GetBucketLifecycle(const GetBucketLifecycleReq& request, GetBucketLifecycleResp* response);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::GetBucketLifecycleReq req(bucket_name);qcloud_cos::GetBucketLifecycleResp resp;qcloud_cos::CosResult result = cos.GetBucketLifecycle(req, &resp);if (result.IsSucc()) {// 请求成功,通过resp获取生命周期规则} else {// 请求失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等}
参数 | 参数描述 | 类型 | 是否必填 |
req | GetBucketLifecycle 操作的请求 | GetBucketLifecycleReq | 是 |
resp | GetBucketLifecycle 操作的响应 | GetBucketLifecycleResp | 是 |
std::vector<LifecycleRule> GetRules() const;
CosResult CosAPI::DeleteBucketLifecycle(const DeleteBucketLifecycleReq& request, DeleteBucketLifecycleResp* response);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::DeleteBucketLifecycleReq req(bucket_name);qcloud_cos::DeleteBucketLifecycleResp resp;qcloud_cos::CosResult result = cos.DeleteBucketLifecycle(req, &resp);if (result.IsSucc()) {// 请求成功} else {// 请求失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等}
参数 | 参数描述 | 类型 | 是否必填 |
req | DeletBucketLifecycle 操作的请求 | DelettBucketLifecycleReq | 是 |
resp | DeletBucketLifecycle 操作的响应 | DeletBucketLifecycleResp | 是 |
本页内容是否解决了您的问题?