控制台指南

最佳实践

开发者指南

API 文档

SDK 文档

跨地域复制

最近更新时间:2020-11-10 16:01:00

简介

本文档提供关于跨地域复制的 API 概览以及 SDK 示例代码。

API 操作名 操作描述
PUT Bucket replication 设置跨地域复制 设置存储桶的跨地域复制规则
GET Bucket replication 查询跨地域复制 查询存储桶的跨地域复制规则
DELETE Bucket replication 删除跨地域复制 删除存储桶的跨地域复制规则

SDK API 参考

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

设置跨地域复制

功能说明

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

示例代码

string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
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 查看。

查询跨地域复制

功能说明

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

示例代码

string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
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 查看。

删除跨地域复制

功能说明

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

示例代码

string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
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 查看。

目录