控制台指南

最佳实践

开发者指南

数据湖存储

API 文档

SDK 文档

数据库文档捉虫大赛邀您参加,好礼多多> HOT

简介

本文档提供关于存储桶复制的 API 概览以及 SDK 示例代码。

API 操作名 操作描述
PUT Bucket replication 设置存储桶复制 对已启用版本控制的存储桶配置存储桶复制规则
GET Bucket replication 查询存储桶复制 查询存储桶的存储桶复制配置信息
DELETE Bucket replication 删除存储桶复制 删除存储桶的存储桶复制配置信息

设置存储桶复制

功能说明

设置指定存储桶的存储桶复制规则(PUT Bucket replication)。

方法原型

CosResult PutBucketReplication(const PutBucketReplicationReq& request, PutBucketReplicationResp* response);

请求示例

qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config)
;
std::string bucket_name = "examplebucket-1250000000";
qcloud_cos::PutBucketReplicationReq req(bucket_name)
;
qcloud_cos::PutBucketReplicationResp resp;

req.SetRole("qcs::cam::uin/100000000001:uin/100000000001"); // 设置发起者身份
qcloud_cos::ReplicationRule rule("", "qcs::cos:ap-guangzhou:uid/1250000000:destinationbucket-1250000000",
"", "", true)
; // 设置存储桶复制规则
req.AddReplicationRule(rule);

qcloud_cos::CosResult result = cos.PutBucketReplication(req, &resp);

if (result.IsSucc())
{
// 请求成功
} else {
// 请求失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等
}

参数说明

参数 参数描述 类型 是否必填
req PutBucketReplication 操作的请求 PutBucketReplicationReq
resp PutBucketReplication 操作的响应 PutBucketReplicationResp

PutBucketReplicationReq 提供以下方法设置存储桶复制相关信息:

void SetRole(const std::string& role)
void AddReplicationRule(const ReplicationRule& rule)
void SetReplicationRule(const std::vector<ReplicationRule>& rules)

ReplicationRule 的定义如下:

struct ReplicationRule {
  bool m_is_enable;
  std::string m_id; // 用来标注具体 Rule 的名称    
  std::string m_prefix;  // 前缀匹配策略,不可重叠,重叠返回错误
  std::string m_dest_bucket;  // 目标存储桶信息    
  std::string m_dest_storage_class;  // 存储类型,枚举值:STANDARD,STANDARD_IA

查询存储桶复制

功能说明

查询指定存储桶的存储桶复制规则(GET Bucket replication)。

方法原型

CosResult GetBucketReplication(const GetBucketReplicationReq& request, GetBucketReplicationResp* response);

请求示例

qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000";
qcloud_cos::GetBucketReplicationReq req(bucket_name);
qcloud_cos::GetBucketReplicationResp resp;
qcloud_cos::CosResult result = cos.GetBucketReplication(req, &resp);
if (result.IsSucc()) {
  // 请求成功,调用 resp 方法获取存储桶复制规则
} else {
  // 请求失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等
} 

参数说明

参数 参数描述 类型 是否必填
req GetBucketReplication 操作的请求 GetBucketReplicationReq
resp GetBucketReplication 操作的响应 GetBucketReplicationResp

GetBucketReplicationResp 提供以下方法获取存储桶复制规则:

std::string GetRole() const;
std::vector<replicationrule> GetRules() const
;

删除存储桶复制

功能说明

删除指定存储桶的存储桶复制规则(DELETE Bucket replication)。

方法原型

CosResult DeleteBucketReplication(const DeleteBucketReplicationReq& request, DeleteBucketReplicationResp* response);

请求示例

qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000";
qcloud_cos::DeleteBucketReplicationReq req(bucket_name);
qcloud_cos::DeleteBucketReplicationResp resp;
qcloud_cos::CosResult result = cos.DeleteBucketReplication(req, &resp);
if (result.IsSucc()) {
  // 请求成功
} else {
  // 请求失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等
} 

参数说明

参数 参数描述 类型 是否必填
req DeleteBucketReplication 操作的请求 DeleteBucketReplicationReq
resp DeleteBucketReplication 操作的响应 DeleteBucketReplicationResp
目录