tencent cloud

masukan

Lifecycle

Terakhir diperbarui:2021-11-30 12:29:43

    Overview

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

    API Operation Description
    PUT Bucket lifecycle Setting lifecycle configuration Sets lifecycle for a bucket
    GET Bucket lifecycle Querying a lifecycle configuration Queries the lifecycle configuration of a bucket
    DELETE Bucket lifecycle Deleting a lifecycle configuration Deletes the lifecycle configuration of a bucket

    SDK API References

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

    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.intl.cloud.tencent.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.intl.cloud.tencent.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.intl.cloud.tencent.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.

    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24