tencent cloud

Feedback

Cross-region replication

Last updated: 2024-01-23 17:15:08

    Overview

    This document provides an overview of APIs and SDK code samples related to cross-region replication.
    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

    SDK API References

    For parameters and method description of all APIs in the SDK, please see SDK API Reference.

    Setting Cross-region Replication Rules

    Description

    This API is used to set the cross-region replication rules of a specified bucket.

    Sample code

    Objective-C
    QCloudPutBucketReplicationRequest* request = [[QCloudPutBucketReplicationRequest alloc] init];
    
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    request.bucket = @"examplebucket-1250000000";
    
    // All cross-region replication configuration information
    QCloudBucketReplicationConfiguation* replConfiguration =
    [[QCloudBucketReplicationConfiguation alloc] init];
    
    // Initiator ID
    replConfiguration.role = @"qcs::cam::uin/100000000001:uin/100000000001";
    
    // Specific configuration information
    QCloudBucketReplicationRule* rule = [[QCloudBucketReplicationRule alloc] init];
    
    // Identify the name of a specific rule
    rule.identifier = @"identifier";
    rule.status = QCloudCOSXMLStatusEnabled;
    
    // Resource ID
    QCloudBucketReplicationDestination* destination = [[QCloudBucketReplicationDestination alloc] init];
    NSString* destinationBucket = @"destinationbucket-1250000000";
    
    // Destination bucket region
    NSString* region = @"ap-beijing";
    destination.bucket = [NSString stringWithFormat:@"qcs::cos:%@::%@",region,destinationBucket];
    
    // Destination bucket information
    rule.destination = destination;
    
    // Prefix matching policy. Policies cannot overlap; otherwise, an error will be returned. The prefix matching root directory is 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 of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    putBucketReplication.bucket = "examplebucket-1250000000";
    
    // All cross-region replication configuration information
    let config = QCloudBucketReplicationConfiguation.init();
    config.role = "qcs::cam::uin/100000000001:uin/100000000001";
    
    // Initiator ID
    let rule = QCloudBucketReplicationRule.init();
    
    // Identify the name of a specific rule
    rule.identifier = "rule1";
    // Indicate whether the rule 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. Policies cannot overlap; otherwise, an error will be returned. The prefix matching root directory is 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.

    Querying Cross-region Replication Rules

    Description

    This API is used to query the cross-region replication rules of a specified bucket.

    Sample code

    Objective-C
    QCloudGetBucketReplicationRequest* request = [[QCloudGetBucketReplicationRequest alloc] init];
    
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    request.bucket = @"examplebucket-1250000000";
    
    [request setFinishBlock:^(QCloudBucketReplicationConfiguation* result,
    NSError* error) {
    // Specific configuration information. A maximum of 1,000 rules are supported. All rules must be directed to one 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.

    Deleting Cross-region Replication Rules

    Description

    This API is used to delete the cross-region replication rules of a specified bucket.

    Sample code

    Objective-C
    QCloudDeleteBucketReplicationRequest* request =
    [[QCloudDeleteBucketReplicationRequest alloc] init];
    
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    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.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support