tencent cloud

Feedback

Lifecycle

Last updated: 2024-02-02 14:36:36

    Overview

    This document provides an overview of APIs and SDK code samples related to lifecycles.
    API
    Operation
    Description
    Setting lifecycle configuration
    Sets lifecycle for a bucket
    Querying a lifecycle configuration
    Queries the lifecycle configuration of a bucket
    Deleting a lifecycle configuration
    Deletes the lifecycle configuration of a bucket

    Setting a Lifecycle Configuration

    Description

    This API is used to set the lifecycle configuration of a specified bucket.

    Sample code

    try
    {
    // Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.tencentcloud.com/developer.
    string bucket = "examplebucket-1250000000";
    PutBucketLifecycleRequest request = new PutBucketLifecycleRequest(bucket);
    // Set the lifecycle
    LifecycleConfiguration.Rule rule = new LifecycleConfiguration.Rule();
    rule.id = "lfiecycleConfigureId";
    rule.status = "Enabled"; //Enabled,Disabled
    
    rule.filter = new COSXML.Model.Tag.LifecycleConfiguration.Filter();
    rule.filter.prefix = "2/";
    
    // Specify the operation for deleting expired parts
    rule.abortIncompleteMultiUpload = new LifecycleConfiguration.AbortIncompleteMultiUpload();
    rule.abortIncompleteMultiUpload.daysAfterInitiation = 2;
    
    request.SetRule(rule);
    
    // Execute the request
    PutBucketLifecycleResult result = cosXml.PutBucketLifecycle(request);
    // Request succeeded
    Console.WriteLine(result.GetResultInfo());
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    // Request failed
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    // Request failed
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    Note:
    For the complete sample, go to GitHub.

    Querying a Lifecycle Configuration

    Description

    This API is used to query the lifecycle management configuration of a bucket.

    Sample code

    try
    {
    // Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.tencentcloud.com/developer.
    string bucket = "examplebucket-1250000000";
    GetBucketLifecycleRequest request = new GetBucketLifecycleRequest(bucket);
    // Execute the request
    GetBucketLifecycleResult result = cosXml.GetBucketLifecycle(request);
    // Bucket lifecycle configuration
    LifecycleConfiguration conf = result.lifecycleConfiguration;
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    // Request failed
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    // Request failed
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    Note:
    For the complete sample, go to GitHub.

    Deleting a Lifecycle Configuration

    Description

    This API is used to delete the lifecycle management configuration of a bucket.

    Sample code

    try
    {
    // Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.tencentcloud.com/developer.
    string bucket = "examplebucket-1250000000";
    DeleteBucketLifecycleRequest request = new DeleteBucketLifecycleRequest(bucket);
    // Execute the request
    DeleteBucketLifecycleResult result = cosXml.DeleteBucketLifecycle(request);
    // Request succeeded
    Console.WriteLine(result.GetResultInfo());
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    // Request failed
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    // Request failed
    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