tencent cloud

文档反馈

跨地域复制

最后更新时间:2024-01-19 11:57:11

    简介

    本文档提供关于跨地域复制的 API 概览以及 SDK 示例代码。
    API
    操作名
    操作描述
    设置跨地域复制
    设置存储桶的跨地域复制规则
    查询跨地域复制
    查询存储桶的跨地域复制规则
    删除跨地域复制
    删除存储桶的跨地域复制规则

    SDK API 参考

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

    设置跨地域复制

    功能说明

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

    示例代码

    Objective-C
    QCloudPutBucketReplicationRequest* request = [[QCloudPutBucketReplicationRequest alloc] init];
    
    // 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket
    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 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket
    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 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket
    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 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket
    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 查看。
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持