This document provides an overview of APIs and SDK code samples related to cross-region replication.
API | Operation | Description |
---|---|---|
PUT Bucket replication | Setting cross-region replication rule | Sets a cross-region replication rule for a bucket |
GET Bucket replication | Querying cross-region replication rule | Queries the cross-region replication rule of a bucket |
DELETE Bucket replication | Deleting 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, please see SDK API Reference.
This API is used to set a cross-region replication rule for a specified bucket.
Objective-C
QCloudPutBucketReplicationRequest* request = [[QCloudPutBucketReplicationRequest alloc] init];
// Bucket name in the format: `BucketName-APPID`
request.bucket = @"examplebucket-1250000000";
// Specify all information on the cross-region replication configuration
QCloudBucketReplicationConfiguation* replConfiguration =
[[QCloudBucketReplicationConfiguation alloc] init];
// Initiator ID
replConfiguration.role = @"qcs::cam::uin/100000000001:uin/100000000001";
// Specific configuration information
QCloudBucketReplicationRule* rule = [[QCloudBucketReplicationRule alloc] init];
// Identifier of a specific rule
rule.identifier = @"identifier";
rule.status = QCloudCOSXMLStatusEnabled;
// Resource ID
QCloudBucketReplicationDestination* destination = [[QCloudBucketReplicationDestination alloc] init];
NSString* destinationBucket = @"destinationbucket-1250000000";
// Region of the destination bucket
NSString* region = @"ap-beijing";
destination.bucket = [NSString stringWithFormat:@"qcs::cos:%@::%@",region,destinationBucket];
// Destination bucket information
rule.destination = destination;
// Prefix matching policy. Prefixes cannot overlap; otherwise, an error will be returned. The root directory for prefix matching should be empty
rule.prefix = @"prefix1";
replConfiguration.rule = @[rule];
request.configuation = replConfiguration;
[request setFinishBlock:^(id outputObject, NSError* error) {
// `outputObject` contains all the HTTP response headers
NSDictionary* info = (NSDictionary *) outputObject;
}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketRelication:request];
Note:
For the complete sample, go to GitHub.
Swift
let putBucketReplication = QCloudPutBucketReplicationRequest.init();
// Bucket name in the format: `BucketName-APPID`
putBucketReplication.bucket = "examplebucket-1250000000";
// Specify all information on the cross-region replication configuration
let config = QCloudBucketReplicationConfiguation.init();
config.role = "qcs::cam::uin/100000000001:uin/100000000001";
// Initiator ID
let rule = QCloudBucketReplicationRule.init();
// Identifier of a specific rule
rule.identifier = "rule1";
// Indicate whether the configuration is enabled. Valid values: .enabled, .disabled
rule.status = .enabled;
// Destination bucket information
let destination = QCloudBucketReplicationDestination.init();
let destinationBucket = "destinationbucket-1250000000";
let region = "ap-beijing";
destination.bucket = "qcs::cos:\(region)::\(destinationBucket)";
rule.destination = destination;
// Prefix matching policy. Prefixes cannot overlap; otherwise, an error will be returned. The root directory for prefix matching should be empty
rule.prefix = "dir/";
config.rule = [rule];
putBucketReplication.configuation = config;
putBucketReplication.finishBlock = {(result,error) in
if let result = result {
// “result” contains response headers
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().putBucketRelication(putBucketReplication);
Note:
For the complete sample, go to GitHub.
This API is used to query the cross-region replication rule of a specified bucket.
Objective-C
QCloudGetBucketReplicationRequest* request = [[QCloudGetBucketReplicationRequest alloc] init];
// Bucket name in the format: `BucketName-APPID`
request.bucket = @"examplebucket-1250000000";
[request setFinishBlock:^(QCloudBucketReplicationConfiguation* result,
NSError* error) {
// Specific configuration information. You can set up to 1,000 rules, all of which must point to the same single destination bucket
NSArray *rules = result.rule;
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucketReplication:request];
Note:
For the complete sample, go to GitHub.
Swift
let getBucketReplication = QCloudGetBucketReplicationRequest.init();
getBucketReplication.bucket = "examplebucket-1250000000";
getBucketReplication.setFinish { (config, error) in
if let config = config {
// List all the rules
let rule = config.rule
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().getBucketReplication(getBucketReplication);
Note:
For the complete sample, go to GitHub.
This API is used to delete the cross-region replication rule from a specified bucket.
Objective-C
QCloudDeleteBucketReplicationRequest* request =
[[QCloudDeleteBucketReplicationRequest alloc] init];
// Bucket name in the format: `BucketName-APPID`
request.bucket = @"examplebucket-1250000000";
[request setFinishBlock:^(id outputObject, NSError* error) {
// `outputObject` contains all the HTTP response headers
NSDictionary* info = (NSDictionary *) outputObject;
}];
[[QCloudCOSXMLService defaultCOSXML] DeleteBucketReplication:request];
Note:
For the complete sample, go to GitHub.
Swift
let deleteBucketReplication = QCloudDeleteBucketReplicationRequest.init();
deleteBucketReplication.bucket = "examplebucket-1250000000";
deleteBucketReplication.finishBlock = {(result,error) in
if let result = result {
// “result” contains response headers
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().deleteBucketReplication(deleteBucketReplication);
Note:
For the complete sample, go to GitHub.
Was this page helpful?