Cross-region Replication

Last updated: 2020-03-25 15:55:11

PDF

Note

This document provides an overview of API on cross-regional replication and sample SDK code.

API Operation name pedagogical operation
PUT Bucket replication Setting Cross-region Replication Set Bucket's cross-region replication rules
GET Bucket replication Query cross-region replication Query Bucket's cross-region replication rules
DELETE Bucket replication Delete cross-region replication Delete Bucket's cross-region replication rule

Setting Cross-region Replication

Function description

Sets the cross-region replication rules for the specified Bucket.

Method prototype

PutBucketReplicationResult PutBucketReplication(PutBucketReplicationRequest request);
void PutBucketReplication(PutBucketReplicationRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("COS_REGION") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;          
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

string bucket = "examplebucket-1250000000"; 
string ownerUin = "100000000001"; 
string subUin = "100000000001"; 
PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket);
PutBucketReplicationRequest.RuleStruct ruleStruct = 
  new PutBucketReplicationRequest.RuleStruct();
ruleStruct.id = "replication_01"; 
ruleStruct.isEnable = true; 
ruleStruct.appid = "1250000000"; 
ruleStruct.region = "ap-beijing"; 
ruleStruct.bucket = "destinationbucket-1250000000"; 
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());
}

Parameter description

Parameter name Description Type
Bucket Source Bucket, format: BucketName-APPID, please see Naming convention String
OwnerUin Initiator ID: OwnerUin String
SubUin Initiator ID: SubUin String
RuleStruct Signed request parameters RuleStruct
SignStartTimeSecond Start time of signature validity (Unix timestamp), for example, 1557902800 Long
DurationSecond The validity period of the signature (in seconds). For example, the validity period of the signature is 1 minute: 60. Long
HeaderKeys Signed request header List<string>
QueryParameterKeys Signed request parameters List<string>

Return result description

The request result is returned through PutBucketReplicationResult.

Member variable Type Description
HttpCode Int HTTP Code, [200,300) indicates that the operation was successful, otherwise it indicates that the operation failed. When the operation fails, the system throws a CosClientException or CosServerException Abnormal.

Query cross-region replication

Function description

Query the cross-region replication rules of specified Bucket.

Method prototype

GetBucketReplicationResult GetBucketReplication(GetBucketReplicationRequest request);
void GetBucketReplication(GetBucketReplicationRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("COS_REGION") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;          
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

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());
}

Parameter description

Parameter name Description Type
Bucket Query Bucket copied across regions. Format: BucketName-APPID,. For more information, please see Naming convention String
SignStartTimeSecond Start time of signature validity (Unix timestamp), for example, 1557902800 Long
DurationSecond The validity period of the signature (in seconds). For example, the validity period of the signature is 1 minute: 60. Long
HeaderKeys Signed request header List<string>
QueryParameterKeys Signed request parameters List<string>

Return result description

The request result is returned through GetBucketReplicationResult.

Member variable Type Description
HttpCode Int HTTP Code, [200,300) indicates that the operation was successful, otherwise it indicates that the operation failed. ReplicationConfiguration[

When the operation fails, the system throws a CosClientException or CosServerException Abnormal.

Delete cross-region replication

Function description

Delete the cross-region replication rule of the specified Bucket.

Method prototype

DeleteBucketReplicationResult DeleteBucketReplication(DeleteBucketReplicationRequest request);
void DeleteBucketReplication(DeleteBucketReplicationRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("COS_REGION") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;        
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

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());
}

Parameter description

Parameter name Description Type
Bucket Delete Bucket copied across regions. Format: BucketName-APPID,. For more information, please see Naming convention String
SignStartTimeSecond Start time of signature validity (Unix timestamp), for example, 1557902800 Long
DurationSecond The validity period of the signature (in seconds). For example, the validity period of the signature is 1 minute: 60. Long
HeaderKeys Signed request header List<string>
QueryParameterKeys Signed request parameters List<string>

Return result description

The request result is returned through DeleteBucketReplicationResult.

Member variable Type Description
HttpCode Int HTTP Code, [200,300) indicates that the operation was successful, otherwise it indicates that the operation failed. When the operation fails, the system throws a CosClientException or CosServerException Abnormal.