API | Operation | Description |
Setting a cross-region replication rule | Sets a cross-region replication rule for a bucket | |
Querying a cross-region replication rule | Queries the cross-region replication rule of a bucket | |
Deleting a cross-region replication rule | Deletes the cross-region replication rule from a bucket |
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";PutBucketReplicationRequest putBucketReplicationRequest =new PutBucketReplicationRequest(bucket);string ownerUin = "100000000001"; //Replication initiator identifier: OwnerUinstring subUin = "100000000001"; //Replication initiator identifier: SubUinputBucketReplicationRequest.setReplicationConfigurationWithRole(ownerUin,subUin);PutBucketReplicationRequest.RuleStruct ruleStruct =new PutBucketReplicationRequest.RuleStruct();// Identify the name of a specific ruleruleStruct.id = "replication_01";//Identify whether to enable the rule. true: enabled; false: disabledruleStruct.isEnable = true;// Destination bucket regionruleStruct.region = "ap-beijing";// Destination bucketruleStruct.bucket = "destinationbucket-1250000000";// Prefix matching policyruleStruct.prefix = "dir/";putBucketReplicationRequest.setReplicationConfigurationWithRule(ruleStruct);cosXmlService.putBucketReplicationAsync(putBucketReplicationRequest,new CosXmlResultListener() {@Overridepublic 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?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";GetBucketReplicationRequest getBucketReplicationRequest =new GetBucketReplicationRequest(bucket);cosXmlService.getBucketReplicationAsync(getBucketReplicationRequest,new CosXmlResultListener() {@Overridepublic 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?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";DeleteBucketReplicationRequest deleteBucketReplicationRequest =new DeleteBucketReplicationRequest(bucket);cosXmlService.deleteBucketReplicationAsync(deleteBucketReplicationRequest,new CosXmlResultListener() {@Overridepublic 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?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Was this page helpful?