Life Cycle

Last updated: 2020-03-25 16:01:07

PDF

Note

This document provides an overview of the API lifecycle and sample SDK code.

API Operation name pedagogical operation
PUT Bucket lifecycle Setting Lifecycle Set up the configuration of Bucket's life cycle management
GET Bucket lifecycle Query life cycle Query the configuration of Bucket's life cycle management
DELETE Bucket lifecycle Delete Lifecycle Delete Bucket's life cycle management configuration

Setting Lifecycle

Function description

Sets the lifecycle configuration information for the specified Bucket.

Method prototype

PutBucketLifecycleResult PutBucketLifecycle(PutBucketLifecycleRequest request);

void PutBucketLifecycle(PutBucketLifecycleRequest 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);

try
{
  string bucket = "examplebucket-1250000000"; 
  PutBucketLifecycleRequest request = new PutBucketLifecycleRequest(bucket);
  request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
  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/";

  rule.abortIncompleteMultiUpload = new LifecycleConfiguration.AbortIncompleteMultiUpload();
  rule.abortIncompleteMultiUpload.daysAfterInitiation = 2;

  request.SetRule(rule);

  PutBucketLifecycleResult result = cosXml.PutBucketLifecycle(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 Setting method Description Type
Bucket Construction method Set the life cycle of Bucket, format: BucketName-APPID String
Rule SetRule Set Bucket's life cycle configuration LifecycleConfiguration.Rule
SignStartTimeSecond SetSign Start time of signature validity (Unix timestamp), for example, 1557902800 Long
DurationSecond SetSign The validity period of the signature (in seconds). For example, the validity period of the signature is 1 minute: 60. Long
HeaderKeys SetSign Signed request headerList<string> QueryParameterKeys

Request result is returned through PutBucketLifecycleResult.

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

Query life cycle

Function description

Query Bucket's lifecycle management configuration.

Method prototype

GetBucketLifecycleResult GetBucketLifecycle(GetBucketLifecycleRequest request);

void GetBucketLifecycle(GetBucketLifecycleRequest 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);

try
{
  string bucket = "examplebucket-1250000000"; 
  GetBucketLifecycleRequest request = new GetBucketLifecycleRequest(bucket);
  request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
  GetBucketLifecycleResult result = cosXml.GetBucketLifecycle(request);
  LifecycleConfiguration conf = result.lifecycleConfiguration;
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

Parameter description

Parameter name Setting method Description Type
Bucket Construction method Query the lifecycle of Bucket, format: BucketName-APPID String
SignStartTimeSecond SetSign Start time of signature validity (Unix timestamp), for example, 1557902800 Long
DurationSecond SetSign The validity period of the signature (in seconds). For example, the validity period of the signature is 1 minute: 60. Long
HeaderKeys SetSign Signed request headerList<string> QueryParameterKeys

Request result is returned through GetBucketLifecycleResult.

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

Delete Lifecycle

Function description

Delete Bucket lifecycle management configuration.

Method prototype

DeleteBucketLifecycleResult DeleteBucketLifecycle(DeleteBucketLifecycleRequest request);

void DeleteBucketLifecycle(DeleteBucketLifecycleRequest 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);

try
{
  string bucket = "examplebucket-1250000000"; 
  DeleteBucketLifecycleRequest request = new DeleteBucketLifecycleRequest(bucket);
  request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
  DeleteBucketLifecycleResult result = cosXml.DeleteBucketLifecycle(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 Setting method Description Type
Bucket Construction method Bucket with deleted lifecycle configuration, format: BucketName-APPID String
SignStartTimeSecond SetSign Start time of signature validity (Unix timestamp), for example, 1557902800 Long
DurationSecond SetSign The validity period of the signature (in seconds). For example, the validity period of the signature is 1 minute: 60. Long
HeaderKeys SetSign Signed request headerList<string> QueryParameterKeys

Request result is returned through DeleteBucketLifecycleResult.

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