tencent cloud

文档反馈

跨地域复制

最后更新时间:2024-01-05 14:14:08

    简介

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

    设置跨地域复制

    功能说明

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

    示例代码

    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    string ownerUin = "100000000001"; //发起者身份标示: OwnerUin
    string subUin = "100000000001"; //发起者身份标示: SubUin
    PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket);
    //设置 replication
    PutBucketReplicationRequest.RuleStruct ruleStruct =
    new PutBucketReplicationRequest.RuleStruct();
    ruleStruct.id = "replication_01"; //用来标注具体 Rule 的名称
    ruleStruct.isEnable = true; //标识 Rule 是否生效 :true, 生效; false, 不生效
    ruleStruct.appid = "1250000000"; //APPID
    ruleStruct.region = "ap-beijing"; //目标存储桶地域信息
    ruleStruct.bucket = "destinationbucket-1250000000"; //格式:BucketName-APPID
    ruleStruct.prefix = "34"; //前缀匹配策略
    List<PutBucketReplicationRequest.RuleStruct> ruleStructs =
    new List<PutBucketReplicationRequest.RuleStruct>();
    ruleStructs.Add(ruleStruct);
    request.SetReplicationConfiguration(ownerUin, subUin, ruleStructs);
    
    try
    {
    PutBucketReplicationResult result = cosXml.PutBucketReplication(request);
    Console.WriteLine(result.GetResultInfo());
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    说明
    更多完整示例,请前往 GitHub 查看。

    查询跨地域复制

    功能说明

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

    示例代码

    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    GetBucketReplicationRequest request = new GetBucketReplicationRequest(bucket);
    try
    {
    GetBucketReplicationResult result = cosXml.GetBucketReplication(request);
    // 存储桶的跨区域复制配置
    ReplicationConfiguration conf = result.replicationConfiguration;
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    说明
    更多完整示例,请前往 GitHub 查看。

    删除跨地域复制

    功能说明

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

    示例代码

    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    DeleteBucketReplicationRequest request = new DeleteBucketReplicationRequest(bucket);
    try
    {
    DeleteBucketReplicationResult result = cosXml.DeleteBucketReplication(request);
    Console.WriteLine(result.GetResultInfo());
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    说明
    更多完整示例,请前往 GitHub 查看。
    联系我们

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

    技术支持

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

    7x24 电话支持