存储桶标签

最后更新时间:2020-11-11 15:36:07

    简介

    本文档提供关于存储桶标签的 API 概览以及 SDK 示例代码。

    API 操作名 操作描述
    PUT Bucket tagging 设置存储桶标签 为已存在的存储桶设置标签
    GET Bucket tagging 查询存储桶标签 查询指定存储桶下已有的存储桶标签
    DELETE Bucket tagging 删除存储桶标签 删除指定的存储桶标签

    SDK API 参考

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

    设置存储桶标签

    功能说明

    PUT Bucket tagging 用于为已存在的存储桶设置标签。

    示例代码

    try
    {
      string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
      PutBucketTaggingRequest request = new PutBucketTaggingRequest(bucket);
      string akey = "aTagKey";
      string avalue = "aTagValue";
      string bkey = "bTagKey";
      string bvalue = "bTagValue";
    
      request.AddTag(akey, avalue);
      request.AddTag(bkey, bvalue);
    
      //执行请求
      PutBucketTaggingResult result = cosXml.putBucketTagging(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 查看。

    查询存储桶标签

    功能说明

    GET Bucket tagging 用于查询指定存储桶下已有的存储桶标签。

    示例代码

    try
    {
      string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
      GetBucketTaggingRequest request = new GetBucketTaggingRequest(bucket);   
      //执行请求
      GetBucketTaggingResult result = cosXml.getBucketTagging(request);
    
      //请求成功
      Tagging tagging = result.tagging;
      Console.WriteLine(tagging);
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
      //请求失败
      Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
      //请求失败
      Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }

    说明:

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

    删除存储桶标签

    功能说明

    DELETE Bucket tagging 用于删除指定存储桶下已有的存储桶标签。

    示例代码

    try
    {
      string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
      DeleteBucketTaggingRequest request = new DeleteBucketTaggingRequest(bucket);   
      //执行请求
      DeleteBucketTaggingResult result = cosXml.deleteBucketTagging(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?

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

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