Versioning

Last updated: 2020-03-25 15:40:17

PDF

Note

This document provides an overview of API on version control and sample SDK code.

API Operation name pedagogical operation
PUT Bucket versioning Setting Versioning Set Bucket's version control function
GET Bucket versioning Query version control Query Bucket's version control information

Setting Versioning

Function description

Set and specify Bucket's version control function.

Method prototype

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

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("COS_REGION") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;          
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

string bucket = "examplebucket-1250000000"; 
PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket);
request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
request.IsEnableVersionConfig(true); 

try
{
  PutBucketVersioningResult result = cosXml.PutBucketVersioning(request);
  Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

Parameter description

Parameter name Description Type
Bucket Bucket who turns on or pauses version control. Format: BucketName-APPID,. For more information, please see Naming convention String
IsEnable Whether to enable version control:
  • True: enabled
  • False: pause
  • Bool
    SignStartTimeSecond Start time of signature validity (Unix timestamp), for example, 1557902800 Long
    DurationSecond The validity period of the signature (in seconds). For example, the validity period of the signature is 1 minute: 60. Long
    HeaderKeys Signed request header List<string>
    QueryParameterKeys Signed request parameters List<string>

    Return result description

    The request result is returned through PutBucketVersioningResult.

    Member variable Type Description
    HttpCode Int HTTP Code,
    [200,300) indicates that the operation was successful, otherwise it indicates that the operation failed. When the operation fails, the system throws a CosClientException or CosServerException Abnormal.

    Query version control

    Function description

    Query the version control information of the specified Bucket.

    Method prototype

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

    Request Sample

    CosXmlConfig config = new CosXmlConfig.Builder()
      .SetConnectionTimeoutMs(60000)  
      .SetReadWriteTimeoutMs(40000)  
      .IsHttps(true)  
      .SetAppid("1250000000") 
      .SetRegion("COS_REGION") 
      .Build();
    
    string secretId = "COS_SECRETID";   
    string secretKey = "COS_SECRETKEY"; 
    long durationSecond = 600;         
    QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
      secretKey, durationSecond);
    
    CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);
    
    string bucket = "examplebucket-1250000000"; 
    GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket);
    
    try
    {
      GetBucketVersioningResult result = cosXml.GetBucketVersioning(request);
      VersioningConfiguration conf =  result.versioningConfiguration;
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
      Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
      Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }

    Parameter description

    Parameter name Description Type
    Bucket Query Bucket for version control. Format: BucketName-APPID,. For more information, please see Naming convention String
    SignStartTimeSecond Start time of signature validity (Unix timestamp), for example, 1557902800 Long
    DurationSecond The validity period of the signature (in seconds). For example, the validity period of the signature is 1 minute: 60. Long
    HeaderKeys Signed request header List<string>
    QueryParameterKeys Signed request parameters List<string>

    Return result description

    The request result is returned through GetBucketVersioningResult.

    Member variable Type Description
    HttpCode Int HTTP Code, [200,300) indicates that the operation was successful, otherwise it indicates that the operation failed.

    When the operation fails, the system throws a CosClientException or CosServerException Abnormal.