生命周期

最后更新时间:2020-08-25 15:37:23

    简介

    本文档提供关于生命周期的 API 概览以及 SDK 示例代码。

    API 操作名 操作描述
    PUT Bucket lifecycle 设置生命周期 设置存储桶的生命周期管理的配置
    GET Bucket lifecycle 查询生命周期 查询存储桶生命周期管理的配置
    DELETE Bucket lifecycle 删除生命周期 删除存储桶生命周期管理的配置

    SDK API 参考

    SDK 所有接口的具体参数与方法说明,请参考 SDK API

    设置生命周期

    功能说明

    设置指定存储桶的生命周期配置信息。

    示例代码

    try
    {
      string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
      PutBucketLifecycleRequest request = new PutBucketLifecycleRequest(bucket);
      //设置 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/";
    
      //指定分片过期删除操作
      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());
    }

    说明:

    更多完整示例,请前往 GitHub 查看。

    查询生命周期

    功能说明

    查询存储桶的生命周期管理配置。

    示例代码

    try
    {
      string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
      GetBucketLifecycleRequest request = new GetBucketLifecycleRequest(bucket);
      //执行请求
      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());
    }

    说明:

    更多完整示例,请前往 GitHub 查看。

    删除生命周期

    功能说明

    删除存储桶生命周期管理的配置。

    示例代码

    try
    {
      string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
      DeleteBucketLifecycleRequest request = new DeleteBucketLifecycleRequest(bucket);
      //执行请求
      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());
    }

    说明:

    更多完整示例,请前往 GitHub 查看。

    Was this page helpful?

    本页内容是否解决了您的问题?

    • 完全没帮助
    • 文档较差
    • 文档一般
    • 文档不错
    • 文档很好
    反馈
    帮助