Bucket tag

Last updated: 2020-08-11 10:10:26

    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 SDK API References.

    Setting Bucket Tags

    API description

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

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    PutBucketTaggingRequest putBucketTaggingRequest =
            new PutBucketTaggingRequest(bucket);
    // Set a tag
    putBucketTaggingRequest.addTag("key", "value");
    putBucketTaggingRequest.addTag("hello", "world");
    
    cosXmlService.putBucketTaggingAsync(putBucketTaggingRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            PutBucketTaggingResult putBucketTaggingResult =
                    (PutBucketTaggingResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           CosXmlServiceException serviceException) {
            if (clientException != null) {
                clientException.printStackTrace();
            } else {
                serviceException.printStackTrace();
            }
        }
    });

    Note:

    For more samples, go to GitHub.

    Querying Bucket Tags

    API description

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

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    GetBucketTaggingRequest getBucketTaggingRequest =
            new GetBucketTaggingRequest(bucket);
    
    cosXmlService.getBucketTaggingAsync(getBucketTaggingRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            GetBucketTaggingResult getBucketTaggingResult =
                    (GetBucketTaggingResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           CosXmlServiceException serviceException) {
            if (clientException != null) {
                clientException.printStackTrace();
            } else {
                serviceException.printStackTrace();
            }
        }
    });

    Note:

    For more samples, go to GitHub.

    Deleting Bucket Tags

    API description

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

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    DeleteBucketTaggingRequest deleteBucketTaggingRequest =
            new DeleteBucketTaggingRequest(bucket);
    
    cosXmlService.deleteBucketTaggingAsync(deleteBucketTaggingRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            DeleteBucketTaggingResult getBucketTaggingResult =
                    (DeleteBucketTaggingResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           CosXmlServiceException serviceException) {
            if (clientException != null) {
                clientException.printStackTrace();
            } else {
                serviceException.printStackTrace();
            }
    
        }
    });

    Note:

    For more samples, go to GitHub.

    Was this page helpful?

    Was this page helpful?

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