tencent cloud

Feedback

Versioning

Last updated: 2021-11-30 12:29:43

    Overview

    This document provides an overview of APIs and SDK code samples related to versioning.

    API Operation Description
    PUT Bucket versioning Setting versioning Sets versioning for a bucket
    GET Bucket versioning Querying versioning Queries the versioning information of a bucket

    SDK API References

    For the parameters and method description of all the APIs in the SDK, see API Documentation.

    Setting versioning

    Description

    This API is used to set the versioning configuration of a specified bucket. Once enabled, versioning can only be suspended but not disabled.

    Sample code

    // Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.intl.cloud.tencent.com/developer.
    string bucket = "examplebucket-1250000000";
    PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket);
    request.IsEnableVersionConfig(true); //true: enable versioning; false: suspend versioning
    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());
    }
    
    Note:

    For the complete sample, go to GitHub.

    Querying versioning

    Description

    This API is used to query the versioning configuration of a specified bucket.

    • To get the versioning status of a bucket, you need to have read permission for the bucket.
    • There are three versioning statuses: not enabled, enabled, and suspended.

    Sample code

    // Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.intl.cloud.tencent.com/developer.
    string bucket = "examplebucket-1250000000";
    GetBucketVersioningRequest request = new GetBucketVersioningRequest(bucket);
    try
    {
     GetBucketVersioningResult result = cosXml.GetBucketVersioning(request);
     // Bucket lifecycle configuration
     VersioningConfiguration conf =  result.versioningConfiguration;
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
     Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
     Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    
    Note:

    For the complete sample, go to GitHub.

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support