有奖:文档满意度调查问卷,诚邀您填写> HOT

简介

本文档提供关于存储桶复制的 API 概览以及 SDK 示例代码。
API
操作名
操作描述
设置存储桶复制
设置存储桶的存储桶复制规则
查询存储桶复制
查询存储桶的存储桶复制规则
删除存储桶复制
删除存储桶的存储桶复制规则

SDK API 参考

SDK 所有接口的具体参数与方法说明,请参考 SDK API

设置存储桶复制

功能说明

设置指定存储桶的存储桶复制规则。

示例代码

// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
string bucket = "examplebucket-1250000000";
string ownerUin = "100000000001"; //发起者身份标示: OwnerUin
string subUin = "100000000001"; //发起者身份标示: SubUin
PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket);
//设置 replication
PutBucketReplicationRequest.RuleStruct ruleStruct =
new PutBucketReplicationRequest.RuleStruct();
ruleStruct.id = "replication_01"; //用来标注具体 Rule 的名称
ruleStruct.isEnable = true; //标识 Rule 是否生效 :true, 生效; false, 不生效
ruleStruct.appid = "1250000000"; //APPID
ruleStruct.region = "ap-beijing"; //目标存储桶地域信息
ruleStruct.bucket = "destinationbucket-1250000000"; //格式:BucketName-APPID
ruleStruct.prefix = "34"; //前缀匹配策略
List<PutBucketReplicationRequest.RuleStruct> ruleStructs =
new List<PutBucketReplicationRequest.RuleStruct>();
ruleStructs.Add(ruleStruct);
request.SetReplicationConfiguration(ownerUin, subUin, ruleStructs);

try
{
PutBucketReplicationResult result = cosXml.PutBucketReplication(request);
Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
说明
更多完整示例,请前往 GitHub 查看。

查询存储桶复制

功能说明

查询指定存储桶的存储桶复制规则。

示例代码

// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
string bucket = "examplebucket-1250000000";
GetBucketReplicationRequest request = new GetBucketReplicationRequest(bucket);
try
{
GetBucketReplicationResult result = cosXml.GetBucketReplication(request);
// 存储桶的跨区域复制配置
ReplicationConfiguration conf = result.replicationConfiguration;
}
catch (COSXML.CosException.CosClientException clientEx)
{
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
说明
更多完整示例,请前往 GitHub 查看。

删除存储桶复制

功能说明

删除指定存储桶的存储桶复制规则。

示例代码

// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
string bucket = "examplebucket-1250000000";
DeleteBucketReplicationRequest request = new DeleteBucketReplicationRequest(bucket);
try
{
DeleteBucketReplicationResult result = cosXml.DeleteBucketReplication(request);
Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
说明
更多完整示例,请前往 GitHub 查看。