存储桶管理

最近更新时间:2019-06-21 16:18:50

简介

本文档提供关于跨域访问、生命周期、版本控制、跨地域复制相关的 API 概览以及 SDK 示例代码。

跨域访问

API 操作名 操作描述
PUT Bucket cors 设置跨域配置 设置存储桶的跨域访问权限
GET Bucket cors 查询跨域配置 查询存储桶的跨域访问配置信息
DELETE Bucket cors 删除跨域配置 删除存储桶的跨域访问配置信息

生命周期

API 操作名 操作描述
PUT Bucket lifecycle 设置生命周期 设置存储桶的生命周期管理的配置
GET Bucket lifecycle 查询生命周期 查询存储桶生命周期管理的配置
DELETE Bucket lifecycle 删除生命周期 删除存储桶生命周期管理的配置

版本控制

API 操作名 操作描述
PUT Bucket versioning 设置版本控制 设置存储桶的版本控制功能
GET Bucket versioning 查询版本控制 查询存储桶的版本控制信息

跨地域复制

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

跨域访问

设置跨域配置

功能说明

设置指定存储桶的跨域访问配置信息。

方法原型

PutBucketCORSResult PutBucketCORS(PutBucketCORSRequest request);

void PutBucketCORS(PutBucketCORSRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

try
{
    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    PutBucketCORSRequest request = new PutBucketCORSRequest(bucket);
    //设置签名有效时长
    request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
    //设置跨域访问配置 CORS
    COSXML.Model.Tag.CORSConfiguration.CORSRule corsRule = new COSXML.Model.Tag.CORSConfiguration.CORSRule();
    corsRule.id = "corsconfigureId";
    corsRule.maxAgeSeconds = 6000;
    corsRule.allowedOrigin = "http://cloud.tencent.com";

    corsRule.allowedMethods = new List<string>();
    corsRule.allowedMethods.Add("PUT");

    corsRule.allowedHeaders = new List<string>();
    corsRule.allowedHeaders.Add("Host");

    corsRule.exposeHeaders = new List<string>();
    corsRule.exposeHeaders.Add("x-cos-meta-x1");

    request.SetCORSRule(corsRule);

    //执行请求
    PutBucketCORSResult result = cosXml.PutBucketCORS(request);
    //请求成功
    Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{    
    //请求失败
     Console.WriteLine("CosClientException: " + clientEx.Message);
}
catch (COSXML.CosException.CosServerException serverEx)
{
    //请求失败
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

/**
//异步方法
string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
PutBucketCORSRequest request = new PutBucketCORSRequest(bucket);
//设置签名有效时长
request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

//设置跨域访问配置 CORS
COSXML.Model.Tag.CORSConfiguration.CORSRule corsRule = new COSXML.Model.Tag.CORSConfiguration.CORSRule();
corsRule.id = "corsconfigureId";
corsRule.maxAgeSeconds = 6000;
corsRule.allowedOrigin = "http://cloud.tencent.com";

corsRule.allowedMethods = new List<string>();
corsRule.allowedMethods.Add("PUT");

corsRule.allowedHeaders = new List<string>();
corsRule.allowedHeaders.Add("Host");

corsRule.exposeHeaders = new List<string>();
corsRule.exposeHeaders.Add("x-cos-meta-x1");

request.SetCORSRule(corsRule);

cosXml.PutBucketCORS(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        PutBucketCORSResult result = cosResult as PutBucketCORSResult;
        Console.WriteLine(result.GetResultInfo());

    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
    });
*/

参数说明

参数名称 设置方法 描述 类型
bucket 构造方法 存储桶名称,格式:BucketName-APPID string
corsRule SetCORSRule 设置存储桶的跨域访问配 CORSConfiguration.CORSRule
signStartTimeSecond SetSign 签名有效期起始时间 long
durationSecond SetSign 签名有效期时长 long
headerKeys SetSign 签名是否校验 header List<string>
queryParameterKeys SetSign 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 PutBucketCORSResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200, 300)之间表示操作成功,否则表示操作失败

查询跨域配置

功能说明

查询指定存储桶的跨域访问配置信息。

方法原型

GetBucketCORSResult GetBucketCORS(GetBucketCORSRequest request);

void GetBucketCORS(GetBucketCORSRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

try
{
    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    GetBucketCORSRequest request = new GetBucketCORSRequest(bucket);
    //设置签名有效时长
    request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
    //执行请求
    GetBucketCORSResult result = cosXml.GetBucketCORS(request);
    //请求成功
    Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{    
    //请求失败
    Console.WriteLine("CosClientException: " + clientEx.Message);
}
catch (COSXML.CosException.CosServerException serverEx)
{
    //请求失败
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

/**
//异步方法
string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
GetBucketCORSRequest request = new GetBucketCORSRequest(bucket);
//设置签名有效时长
request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
//执行请求
cosXml.GetBucketCORS(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        GetBucketCORSResult result = cosResult as GetBucketCORSResult;
        Console.WriteLine(result.GetResultInfo());

    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
});
*/

参数说明

参数名称 设置方法 描述 类型
bucket 构造方法 存储桶名称,格式:BucketName-APPID string
signStartTimeSecond SetSign 签名有效期起始时间 long
durationSecond SetSign 签名有效期时长 long
headerKeys SetSign 签名是否校验 header List<string>
queryParameterKeys SetSign 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 GetBucketCORSResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200, 300)之间表示操作成功,否则表示操作失败
corsConfiguration CORSConfiguration 返回 Bucket 跨域资源共享配置的信息

删除跨域配置

功能说明

删除指定存储桶的跨域访问配置。

方法原型

DeleteBucketCORSResult DeleteBucketCORS(DeleteBucketCORSRequest request);

void DeleteBucketCORS(DeleteBucketCORSRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

try
{
    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    DeleteBucketCORSRequest request = new DeleteBucketCORSRequest(bucket);
    //设置签名有效时长
    request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
    //执行请求
    DeleteBucketCORSResult result = cosXml.DeleteBucketCORS(request);
    //请求成功
    Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{    
    //请求失败
    Console.WriteLine("CosClientException: " + clientEx.Message);
}
catch (COSXML.CosException.CosServerException serverEx)
{
    //请求失败
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

/**
//异步方法
string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
DeleteBucketCORSRequest request = new DeleteBucketCORSRequest(bucket);
//设置签名有效时长
request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
//执行请求
cosXml.DeleteBucketCORS(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        DeleteBucketCORSResult result = cosResult as DeleteBucketCORSResult;
        Console.WriteLine(result.GetResultInfo());

    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
});
*/

参数说明

参数名称 设置方法 描述 类型
bucket 构造方法 存储桶名称,格式:BucketName-APPID string
signStartTimeSecond SetSign 签名有效期起始时间 long
durationSecond SetSign 签名有效期时长 long
headerKeys SetSign 签名是否校验header List<string>
queryParameterKeys SetSign 签名是否校验请求url中查询参数 List<string>

返回结果说明

通过 DeleteBucketCORSResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200, 300)之间表示操作成功,否则表示操作失败

生命周期

设置生命周期

功能说明

设置指定存储桶的生命周期配置信息。

方法原型

PutBucketLifecycleResult PutBucketLifecycle(PutBucketLifecycleRequest request);

void PutBucketLifecycle(PutBucketLifecycleRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

try
{
    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    PutBucketLifecycleRequest request = new PutBucketLifecycleRequest(bucket);
    //设置签名有效时长
    request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
    //设置 lifecycle
    COSXML.Model.Tag.LifecycleConfiguration.Rule rule = new COSXML.Model.Tag.LifecycleConfiguration.Rule();
    rule.id = "lfiecycleConfigureId";
    rule.status = "Enabled"; //Enabled,Disabled

    rule.filter = new COSXML.Model.Tag.LifecycleConfiguration.Filter();
    rule.filter.prefix = "2/";

    //指定分片过期删除操作
    rule.abortIncompleteMultiUpload = new COSXML.Model.Tag.LifecycleConfiguration.AbortIncompleteMultiUpload();
    rule.abortIncompleteMultiUpload.daysAfterInitiation = 2;

    request.SetRule(rule);

    //执行请求
    PutBucketLifecycleResult result = cosXml.PutBucketLifecycle(request);
    //请求成功
    Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{    
    //请求失败
    Console.WriteLine("CosClientException: " + clientEx.Message);
}
catch (COSXML.CosException.CosServerException serverEx)
{
    //请求失败
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

/**
//异步方法
string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
PutBucketLifecycleRequest request = new PutBucketLifecycleRequest(bucket);
//设置签名有效时长
request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
//设置 lifecycle
COSXML.Model.Tag.LifecycleConfiguration.Rule rule = new COSXML.Model.Tag.LifecycleConfiguration.Rule();
rule.id = "lfiecycleConfigureId";
rule.status = "Enabled"; //Enabled,Disabled

rule.filter = new COSXML.Model.Tag.LifecycleConfiguration.Filter();
rule.filter.prefix = "2/";

rule.abortIncompleteMultiUpload = new COSXML.Model.Tag.LifecycleConfiguration.AbortIncompleteMultiUpload();
rule.abortIncompleteMultiUpload.daysAfterInitiation = 2;

request.SetRule(rule);

//执行请求
cosXml.PutBucketLifecycle(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        PutBucketLifecycleResult result = cosResult as PutBucketLifecycleResult;
        Console.WriteLine(result.GetResultInfo());

    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
});
*/

参数说明

参数名称 设置方法 描述 类型
bucket 构造方法 存储桶名称,格式:BucketName-APPID string
rule SetRule 设置存储桶的生命周期配置 LifecycleConfiguration.Rule
signStartTimeSecond SetSign 签名有效期起始时间 long
durationSecond SetSign 签名有效期时长 long
headerKeys SetSign 签名是否校验 header List<string>
queryParameterKeys SetSign 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 PutBucketLifecycleResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200, 300)之间表示操作成功,否则表示操作失败

查询生命周期

功能说明

查询指定存储桶的的生命周期。

方法原型

GetBucketLifecycleResult GetBucketLifecycle(GetBucketLifecycleRequest request);

void GetBucketLifecycle(GetBucketLifecycleRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

try
{
    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    GetBucketLifecycleRequest request = new GetBucketLifecycleRequest(bucket);
    //设置签名有效时长
    request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
    //执行请求
    GetBucketLifecycleResult result = cosXml.GetBucketLifecycle(request);
    //请求成功
    Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{    
    //请求失败
    Console.WriteLine("CosClientException: " + clientEx.Message);
}
catch (COSXML.CosException.CosServerException serverEx)
{
    //请求失败
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

/**
//异步方法
string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
GetBucketLifecycleRequest request = new GetBucketLifecycleRequest(bucket);
//设置签名有效时长
request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
//执行请求
cosXml.GetBucketLifecycle(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
         GetBucketLifecycleResult result = cosResult as GetBucketLifecycleResult;
        Console.WriteLine(result.GetResultInfo());

    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
});
*/

参数说明

参数名称 设置方法 描述 类型
bucket 构造方法 存储桶名称,格式:BucketName-APPID string
signStartTimeSecond SetSign 签名有效期起始时间 long
durationSecond SetSign 签名有效期时长 long
headerKeys SetSign 签名是否校验 header List<string>
queryParameterKeys SetSign 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 GetBucketLifecycleResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200,300)之间表示操作成功,否则表示操作失败
lifecycleConfiguration LifecycleConfiguration 返回 Bucket 的生命周期配置信息

删除生命周期

功能说明

删除指定存储桶的的生命周期。

方法原型

DeleteBucketLifecycleResult DeleteBucketLifecycle(DeleteBucketLifecycleRequest request);

void DeleteBucketLifecycle(DeleteBucketLifecycleRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

try
{
    string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    DeleteBucketLifecycleRequest request = new DeleteBucketLifecycleRequest(bucket);
    //设置签名有效时长
    request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
    //执行请求
    DeleteBucketLifecycleResult result = cosXml.DeleteBucketLifecycle(request);
    //请求成功
    Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{    
    //请求失败
    Console.WriteLine("CosClientException: " + clientEx.Message);
}
catch (COSXML.CosException.CosServerException serverEx)
{
    //请求失败
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

/**
//异步方法
string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
DeleteBucketLifecycleRequest request = new DeleteBucketLifecycleRequest(bucket);
//设置签名有效时长
request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
//执行请求
cosXml.DeleteBucketLifecycle(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        DeleteBucketLifecycleResult result = cosResult as DeleteBucketLifecycleResult;
        Console.WriteLine(result.GetResultInfo());

    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
    });
*/

参数说明

参数名称 设置方法 描述 类型
bucket 构造方法 存储桶名称,格式:BucketName-APPID string
signStartTimeSecond SetSign 签名有效期起始时间 long
durationSecond SetSign 签名有效期时长 long
headerKeys SetSign 签名是否校验 header List<string>
queryParameterKeys SetSign 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 DeleteBucketLifecycleResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200,300)之间表示操作成功,否则表示操作失败

版本控制

设置版本控制

功能说明

设置指定存储桶的版本控制功能。

方法原型

PutBucketVersioningResult PutBucketVersioning(PutBucketVersioningRequest request);
void PutBucketVersioning(PutBucketVersioningRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket);
//设置签名有效时长
//request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
request.IsEnableVersionConfig(true); //true: 开启版本控制; false:暂停版本控制
// 使用同步方法
try {
    PutBucketVersioningResult result = cosXml.PutBucketVersioning(request);
    Console.WriteLine(result.GetResultInfo());
} catch (COSXML.CosException.CosClientException clientEx) {
   Console.WriteLine("CosClientException: " + clientEx.Message);
} catch (COSXML.CosException.CosServerException serverEx) {
   Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
// 使用异步回调请求
cosXml.PutBucketVersioning(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        PutBucketVersioningResult result = cosResult as PutBucketVersioningResult;
        Console.WriteLine(result.GetResultInfo());
    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
    });

参数说明

参数名称 描述 类型
bucket 存储桶名称,格式:BucketName-APPID,详情请参阅 命名规范 string
isEnable 是否开启版本控制: true, 开启; false, 暂停 bool
signStartTimeSecond 签名有效期起始时间 long
durationSecond 签名有效期时长 long
headerKeys 签名是否校验 header List<string>
queryParameterKeys 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 PutBucketVersioningResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200,300)之间表示操作成功,否则表示操作失败

说明:

操作失败时,系统将抛出 CosClientExceptionCosServerException 异常。

查询版本控制

功能说明

查询指定存储桶的版本控制信息。

方法原型

GetBucketVersioningResult GetBucketVersioning(GetBucketVersioningRequest request);
void GetBucketVersioning(GetBucketVersioningRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket);

// 使用同步方法
try {
    GetBucketVersioningResult result = cosXml.GetBucketVersioning(request);
    Console.WriteLine(result.GetResultInfo());
} catch (COSXML.CosException.CosClientException clientEx) {
   Console.WriteLine("CosClientException: " + clientEx.Message);
} catch (COSXML.CosException.CosServerException serverEx) {
   Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

// 使用异步回调请求
cosXml.GetBucketVersioning(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        GetBucketVersioningResult result = cosResult as GetBucketVersioningResult;
        Console.WriteLine(result.GetResultInfo());
    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
    });

参数说明

参数名称 描述 类型
bucket 存储桶名称,格式:BucketName-APPID,详情请参阅 命名规范 string
signStartTimeSecond 签名有效期起始时间 long
durationSecond 签名有效期时长 long
headerKeys 签名是否校验 header List<string>
queryParameterKeys 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 GetBucketVersioningResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200,300)之间表示操作成功,否则表示操作失败
versioningConfiguration VersioningConfiguration 版本控制配置信息

说明:

操作失败时,系统将抛出 CosClientExceptionCosServerException 异常。

跨地域复制

设置跨地域复制

功能说明

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

方法原型

PutBucketReplicationResult PutBucketReplication(PutBucketReplicationRequest request);
void PutBucketReplication(PutBucketReplicationRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
string ownerUin = "ownerUin"; //发起者身份标示:OwnerUin 
string subUin = "SubUin"; //发起者身份标示:SubUin 
PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket);
//设置 replication
putBucketReplicationRequest.setReplicationConfigurationWithRole(ownerUin, subUin);
PutBucketReplicationRequest.RuleStruct ruleStruct = new PutBucketReplicationRequest.RuleStruct();
ruleStruct.id = "replication_01"; //用来标注具体 Rule 的名称
ruleStruct.isEnable = true; //标识 Rule 是否生效 :true, 生效; false, 不生效
ruleStruct.appid = "1250000000"; //appid
ruleStruct.region = Region.AP_Beijing.getRegion(); //目标存储桶地域信息
ruleStruct.bucket = "bucketName"; //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.Message);
} catch (COSXML.CosException.CosServerException serverEx) {
   Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

// 使用异步回调请求
cosXml.PutBucketReplication(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        PutBucketReplicationResult result = cosResult as PutBucketReplicationResult;
        Console.WriteLine(result.GetResultInfo());
    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
    });

参数说明

参数名称 描述 类型
bucket 存储桶名称,格式:BucketName-APPID,详情请参阅 命名规范 string
ownerUin 发起者身份标示:OwnerUin string
subUin 发起者身份标示:SubUin string
ruleStruct 签名是否校验请求 url 中查询参数 RuleStruct
signStartTimeSecond 签名有效期起始时间 long
durationSecond 签名有效期时长 long
headerKeys 签名是否校验 header List<string>
queryParameterKeys 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 PutBucketReplicationResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200,300)之间表示操作成功,否则表示操作失败

说明:

操作失败时,系统将抛出 CosClientExceptionCosServerException 异常。

查询跨地域复制

功能说明

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

方法原型

GetBucketReplicationResult GetBucketReplication(GetBucketReplicationRequest request);
void GetBucketReplication(GetBucketReplicationRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
GetBucketReplicationRequest request = new GetBucketReplicationRequest(bucket);

//使用同步方法
try {
    GetBucketReplicationResult result = cosXml.GetBucketReplication(request);
    Console.WriteLine(result.GetResultInfo());
} catch (COSXML.CosException.CosClientException clientEx) {
   Console.WriteLine("CosClientException: " + clientEx.Message);
} catch (COSXML.CosException.CosServerException serverEx) {
   Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

// 使用异步回调请求
cosXml.GetBucketReplication(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        GetBucketReplicationResult result = cosResult as GetBucketReplicationResult;
        Console.WriteLine(result.GetResultInfo());
    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
    });

参数说明

参数名称 描述 类型
bucket 存储桶名称,格式:BucketName-APPID,详情请参阅 命名规范 string
signStartTimeSecond 签名有效期起始时间 long
durationSecond 签名有效期时长 long
headerKeys 签名是否校验 header List<string>
queryParameterKeys 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 GetBucketReplicationResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200,300)之间表示操作成功,否则表示操作失败
replicationConfiguration ReplicationConfiguration 跨地域配置信息

说明:

操作失败时,系统将抛出 CosClientExceptionCosServerException 异常。

删除跨地域复制

功能说明

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

方法原型

DeleteBucketReplicationResult DeleteBucketReplication(DeleteBucketReplicationRequest request);
void DeleteBucketReplication(DeleteBucketReplicationRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

请求示例

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.Message);
} catch (COSXML.CosException.CosServerException serverEx) {
   Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

// 使用异步回调请求
cosXml.DeleteBucketReplication(request, 
    delegate(COSXML.Model.CosResult cosResult)
    {
        //请求成功
        DeleteBucketReplicationResult result = cosResult as DeleteBucketReplicationResult;
        Console.WriteLine(result.GetResultInfo());
    }, 
    delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx)
    {    
        //请求失败
        if (clientEx != null)
        {
            Console.WriteLine("CosClientException: " + clientEx.Message);
        }
        else if (serverEx != null)
        {
            Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
    });

参数说明

参数名称 描述 类型
bucket 存储桶名称,格式:BucketName-APPID,详情请参阅 命名规范 string
signStartTimeSecond 签名有效期起始时间 long
durationSecond 签名有效期时长 long
headerKeys 签名是否校验 header List<string>
queryParameterKeys 签名是否校验请求 url 中查询参数 List<string>

返回结果说明

通过 DeleteBucketReplicationResult 返回请求结果。

成员变量 类型 描述
httpCode int HTTP Code, [200,300)之间表示操作成功,否则表示操作失败

说明:

操作失败时,系统将抛出 CosClientExceptionCosServerException 异常。