Bucket tag

Last updated: 2020-08-31 16:26:17

    Overview

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

    API Operation Description
    PUT Bucket tagging Setting bucket tags Sets tags for an existing bucket
    GET Bucket tagging Querying bucket tags Queries the existing tags of a specified bucket
    DELETE Bucket tagging Deleting bucket tags Deletes specified bucket tags

    SDK API References

    For the parameters and method descriptions of all the APIs in the SDK, see Api Documentation.

    Setting Bucket Tags

    API description

    This API is used to set tags for an existing bucket.

    Sample code

    try
    {
      String bucket = "examplebucket-1250000000"; // Format: 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);
    
      // Execute the request
      PutBucketTaggingResult result = cosXml.putBucketTagging(request);
    
      // Request successful 
      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 more samples, please visit GitHub.

    Querying Bucket Tags

    API description

    This API is used to query the existing tags of a specified bucket.

    Sample code

    try
    {
      String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
      GetBucketTaggingRequest request = new GetBucketTaggingRequest(bucket);   
      // Execute the request
      GetBucketTaggingResult result = cosXml.getBucketTagging(request);
    
      // Request successful 
      Tagging tagging = result.tagging;
      Console.WriteLine(tagging);
    }
    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 more samples, please visit GitHub.

    Deleting Bucket Tags

    API description

    This API is used to delete the existing tags of a specified bucket.

    Sample code

    try
    {
      String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
      DeleteBucketTaggingRequest request = new DeleteBucketTaggingRequest(bucket);   
      // Execute the request
      DeleteBucketTaggingResult result = cosXml.deleteBucketTagging(request);
    
      // Request successful 
      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 more samples, please visit GitHub.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help