This document provides an overview of APIs and SDK code samples related to cross-region replication.
API | Operation | Description |
---|---|---|
PUT Bucket replication | Setting a cross-region replication rule | Sets a cross-region replication rule for a bucket |
GET Bucket replication | Querying a cross-region replication rule | Queries the cross-region replication rule of a bucket |
DELETE Bucket replication | Deleting a cross-region replication rule | Deletes the cross-region replication rule from a bucket |
For the parameters and method descriptions of all the APIs in the SDK, see SDK API Reference.
This API is used to set the cross-region replication rules of a specified bucket.
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.intl.cloud.tencent.com/cos5/bucket
String bucket = "examplebucket-1250000000";
PutBucketReplicationRequest putBucketReplicationRequest =
new PutBucketReplicationRequest(bucket);
string ownerUin = "100000000001"; //Replication initiator identifier: OwnerUin
string subUin = "100000000001"; //Replication initiator identifier: SubUin
putBucketReplicationRequest.setReplicationConfigurationWithRole(ownerUin,
subUin);
PutBucketReplicationRequest.RuleStruct ruleStruct =
new PutBucketReplicationRequest.RuleStruct();
// Identify the name of a specific rule
ruleStruct.id = "replication_01";
//Identify whether to enable the rule. true: enabled; false: disabled
ruleStruct.isEnable = true;
// Destination bucket region
ruleStruct.region = "ap-beijing";
// Destination bucket
ruleStruct.bucket = "destinationbucket-1250000000";
// Prefix matching policy
ruleStruct.prefix = "dir/";
putBucketReplicationRequest.setReplicationConfigurationWithRule(ruleStruct);
cosXmlService.putBucketReplicationAsync(putBucketReplicationRequest,
new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
PutBucketReplicationResult putBucketReplicationResult =
(PutBucketReplicationResult) result;
}
// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
@Override
public void onFail(CosXmlRequest cosXmlRequest,
@Nullable CosXmlClientException clientException,
@Nullable CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});
Note:For more samples, please visit GitHub.
This API is used to query the cross-region replication rules of a specified bucket.
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.intl.cloud.tencent.com/cos5/bucket
String bucket = "examplebucket-1250000000";
GetBucketReplicationRequest getBucketReplicationRequest =
new GetBucketReplicationRequest(bucket);
cosXmlService.getBucketReplicationAsync(getBucketReplicationRequest,
new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
GetBucketReplicationResult getBucketReplicationResult =
(GetBucketReplicationResult) result;
}
// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
@Override
public void onFail(CosXmlRequest cosXmlRequest,
@Nullable CosXmlClientException clientException,
@Nullable CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});
Note:For more samples, please visit GitHub.
This API is used to delete the cross-region replication rules of a specified bucket.
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.intl.cloud.tencent.com/cos5/bucket
String bucket = "examplebucket-1250000000";
DeleteBucketReplicationRequest deleteBucketReplicationRequest =
new DeleteBucketReplicationRequest(bucket);
cosXmlService.deleteBucketReplicationAsync(deleteBucketReplicationRequest,
new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
DeleteBucketReplicationResult deleteBucketReplicationResult =
(DeleteBucketReplicationResult) result;
}
// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
@Override
public void onFail(CosXmlRequest cosXmlRequest,
@Nullable CosXmlClientException clientException,
@Nullable CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});
Note:For more samples, please visit GitHub.
Was this page helpful?