tencent cloud

Feedback

Versioning

Last updated: 2024-01-23 17:15:08

    Overview

    This document provides an overview of APIs and SDK code samples related to versioning.
    API
    Operation
    Description
    Setting versioning
    Sets versioning for a bucket
    Querying versioning
    Queries the versioning information of a bucket

    SDK API References

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

    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

    Objective-C
    // Enable versioning
    QCloudPutBucketVersioningRequest* request = [[QCloudPutBucketVersioningRequest alloc] init];
    
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    request.bucket =@"examplebucket-1250000000";
    
    // Specific versioning configuration
    QCloudBucketVersioningConfiguration* versioningConfiguration =
    [[QCloudBucketVersioningConfiguration alloc] init];
    
    request.configuration = versioningConfiguration;
    
    // Indicate whether versioning is enabled. Enumerated values: QCloudCOSBucketVersioningStatusEnabled,
    // QCloudCOSBucketVersioningStatusSuspended
    versioningConfiguration.status = QCloudCOSBucketVersioningStatusEnabled;
    
    [request setFinishBlock:^(id outputObject, NSError* error) {
    // `outputObject` contains all the HTTP response headers
    NSDictionary* info = (NSDictionary *) outputObject;
    }];
    [[QCloudCOSXMLService defaultCOSXML] PutBucketVersioning:request];
    Note:
    For the complete sample, go to GitHub.
    Swift
    // Enable versioning
    let putBucketVersioning = QCloudPutBucketVersioningRequest.init();
    
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    putBucketVersioning.bucket = "examplebucket-1250000000";
    
    // Specific versioning configuration
    let config = QCloudBucketVersioningConfiguration.init();
    
    // Indicates whether versioning is enabled. Enumerated values: Suspended, Enabled
    config.status = .enabled;
    
    putBucketVersioning.configuration = config;
    
    putBucketVersioning.finishBlock = {(result,error) in
    if let result = result {
    // "result" contains response headers.
    } else {
    print(error!);
    }
    }
    QCloudCOSXMLService.defaultCOSXML().putBucketVersioning(putBucketVersioning);
    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

    Objective-C
    QCloudGetBucketVersioningRequest* request =
    [[QCloudGetBucketVersioningRequest alloc] init];
    
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    request.bucket = @"examplebucket-1250000000";
    
    [request setFinishBlock:^(QCloudBucketVersioningConfiguration* result,
    NSError* error) {
    // Get the versioning status
    QCloudCOSBucketVersioningStatus * status = result.status;
    }];
    
    [[QCloudCOSXMLService defaultCOSXML] GetBucketVersioning:request];
    Note:
    For the complete sample, go to GitHub.
    Swift
    let getBucketVersioning = QCloudGetBucketVersioningRequest.init();
    
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    getBucketVersioning.bucket = "examplebucket-1250000000";
    
    getBucketVersioning.setFinish { (config, error) in
    if let config = config {
    // Versioning status
    let status = config.status
    } else {
    print(error!);
    }
    
    }
    QCloudCOSXMLService.defaultCOSXML().getBucketVersioning(getBucketVersioning);
    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