跨地域复制

最后更新时间:2020-08-25 17:48:30

    简介

    本文档提供关于跨地域复制的 API 概览以及 SDK 示例代码。

    API 操作名 操作描述
    PUT Bucket replication 设置跨地域复制 设置存储桶的跨地域复制规则
    GET Bucket replication 查询跨地域复制 查询存储桶的跨地域复制规则
    DELETE Bucket replication 删除跨地域复制 删除存储桶的跨地域复制规则

    SDK API 参考

    SDK 所有接口的具体参数与方法说明,请参考 SDK API

    设置跨地域复制

    功能说明

    设置指定存储桶的跨地域复制规则。

    示例代码

    Objective-C

    QCloudPutBucketReplicationRequest* request = [[QCloudPutBucketReplicationRequest alloc] init];
    
    // 存储桶名称,格式为 BucketName-APPID
    request.bucket = @"examplebucket-1250000000";
    
    // 说明所有跨地域配置信息
    QCloudBucketReplicationConfiguation* replConfiguration =
                                [[QCloudBucketReplicationConfiguation alloc] init];
    
    // 发起者身份标示
    replConfiguration.role = @"qcs::cam::uin/100000000001:uin/100000000001";
    
    // 具体配置信息
    QCloudBucketReplicationRule* rule = [[QCloudBucketReplicationRule alloc] init];
    
    // 用来标注具体 Rule 的名称
    rule.identifier = @"identifier";
    rule.status = QCloudCOSXMLStatusEnabled;
    
    // 资源标识符
    QCloudBucketReplicationDestination* destination = [[QCloudBucketReplicationDestination alloc] init];
    NSString* destinationBucket = @"destinationbucket-1250000000";
    
    // 目标存储桶所在地域
    NSString* region = @"ap-beijing";
    destination.bucket = [NSString stringWithFormat:@"qcs::cos:%@::%@",region,destinationBucket];
    
    // 目标存储桶信息
    rule.destination = destination;
    
    // 前缀匹配策略,不可重叠,重叠返回错误。前缀匹配根目录为空
    rule.prefix = @"prefix1";
    replConfiguration.rule = @[rule];
    request.configuation = replConfiguration;
    
    [request setFinishBlock:^(id outputObject, NSError* error) {
        // outputObject 包含所有的响应 http 头部
        NSDictionary* info = (NSDictionary *) outputObject;
    
    }];
    [[QCloudCOSXMLService defaultCOSXML] PutBucketRelication:request];

    说明:

    更多完整示例,请前往 GitHub 查看。

    Swift

    let putBucketReplication = QCloudPutBucketReplicationRequest.init();
    
    // 存储桶名称,格式为 BucketName-APPID
    putBucketReplication.bucket = "examplebucket-1250000000";
    
    // 说明所有跨地域配置信息
    let config = QCloudBucketReplicationConfiguation.init();
    config.role = "qcs::cam::uin/100000000001:uin/100000000001";
    
    // 发起者身份标示
    let rule = QCloudBucketReplicationRule.init();
    
    // 用来标注具体 Rule 的名称
    rule.identifier = "rule1";
    // 规则开启状态,可选 .enabled, .disabled
    rule.status = .enabled;
    
    // 目标存储桶信息
    let destination = QCloudBucketReplicationDestination.init();
    let destinationBucket = "destinationbucket-1250000000";
    let region = "ap-beijing";
    destination.bucket = "qcs::cos:\(region)::\(destinationBucket)";
    rule.destination = destination;
    
    // 前缀匹配策略,不可重叠,重叠返回错误。前缀匹配根目录为空
    rule.prefix = "dir/";
    
    config.rule = [rule];
    
    putBucketReplication.configuation = config;
    
    putBucketReplication.finishBlock = {(result,error) in
        if let result = result {
            // result 包含响应的 header 信息
        } else {
            print(error!);
        }
    }
    QCloudCOSXMLService.defaultCOSXML().putBucketRelication(putBucketReplication);

    说明:

    更多完整示例,请前往 GitHub 查看。

    查询跨地域复制

    功能说明

    查询指定存储桶的跨地域复制规则。

    示例代码

    Objective-C

    QCloudGetBucketReplicationRequest* request = [[QCloudGetBucketReplicationRequest alloc] init];
    
    // 存储桶名称,格式为 BucketName-APPID
    request.bucket = @"examplebucket-1250000000";
    
    [request setFinishBlock:^(QCloudBucketReplicationConfiguation* result,
                              NSError* error) {
        // 具体配置信息,最多支持 1000 个,所有策略只能指向一个目标存储桶
        NSArray *rules = result.rule;
    }];
    [[QCloudCOSXMLService defaultCOSXML] GetBucketReplication:request];

    说明:

    更多完整示例,请前往 GitHub 查看。

    Swift

    let getBucketReplication = QCloudGetBucketReplicationRequest.init();
    getBucketReplication.bucket = "examplebucket-1250000000";
    getBucketReplication.setFinish { (config, error) in
        if let config = config {
            // 配置信息列表
            let rule = config.rule
        } else {
            print(error!);
        }
    }
    QCloudCOSXMLService.defaultCOSXML().getBucketReplication(getBucketReplication);

    说明:

    更多完整示例,请前往 GitHub 查看。

    删除跨地域复制

    功能说明

    删除指定存储桶的跨地域复制规则。

    示例代码

    Objective-C

    QCloudDeleteBucketReplicationRequest* request =
                            [[QCloudDeleteBucketReplicationRequest alloc] init];
    
    // 存储桶名称,格式为 BucketName-APPID
    request.bucket = @"examplebucket-1250000000";
    
    [request setFinishBlock:^(id outputObject, NSError* error) {
        // outputObject 包含所有的响应 http 头部
        NSDictionary* info = (NSDictionary *) outputObject;
    
    }];
    [[QCloudCOSXMLService defaultCOSXML] DeleteBucketReplication:request];

    说明:

    更多完整示例,请前往 GitHub 查看。

    Swift

    let deleteBucketReplication = QCloudDeleteBucketReplicationRequest.init();
    deleteBucketReplication.bucket = "examplebucket-1250000000";
    deleteBucketReplication.finishBlock = {(result,error) in
        if let result = result {
            // result 包含响应的 header 信息
        } else {
            print(error!);
        }
    }
    QCloudCOSXMLService.defaultCOSXML().deleteBucketReplication(deleteBucketReplication);

    说明:

    更多完整示例,请前往 GitHub 查看。

    Was this page helpful?

    本页内容是否解决了您的问题?

    • 完全没帮助
    • 文档较差
    • 文档一般
    • 文档不错
    • 文档很好
    反馈
    帮助