存储桶标签

最后更新时间:2020-08-10 10:32:52

    简介

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

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

    SDK API 参考

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

    设置存储桶标签

    功能说明

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

    示例代码

    String bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
    PutBucketTaggingRequest putBucketTaggingRequest =
            new PutBucketTaggingRequest(bucket);
    // 设置标签
    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();
            }
        }
    });

    说明:

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

    查询存储桶标签

    功能说明

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

    示例代码

    String bucket = "examplebucket-1250000000"; //格式: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();
            }
        }
    });

    说明:

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

    删除存储桶标签

    功能说明

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

    示例代码

    String bucket = "examplebucket-1250000000"; //格式: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();
            }
    
        }
    });

    说明:

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

    Was this page helpful?

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

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