Bucket tag

Last updated: 2020-03-20 12:24:48

PDF

Note

This document provides an overview of API on Bucket tags and sample SDK code.

API Operation name pedagogical operation
PUT Bucket tagging Set Bucket tag Set the label for the existing Bucket
GET Bucket tagging Query Bucket tag Query the existing Bucket tags under the specified Bucket
DELETE Bucket tagging Delete Bucket tag Delete the specified Bucket tag

Set Bucket tag

Function description

PUT Bucket tagging is used to label the existing Bucket.

Method prototype

PutBucketTaggingResult putBucketTagging(PutBucketTaggingRequest request)throws CosXmlClientException, CosXmlServiceException;

void putBucketTaggingAsync(PutBucketTaggingRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
PutBucketTaggingRequest putBucketTaggingRequest = new PutBucketTaggingRequest(bucket);
putBucketTaggingRequest.addTag("key", "value");
putBucketTaggingRequest.addTag("hello", "world");

try {
    PutBucketTaggingResult putBucketTaggingResult = cosXmlService.putBucketTagging(putBucketTaggingRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

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)  {
    }
});

Parameter description

Parameter name Description Type
Bucket Bucket is tagged in BucketName-APPID format. For more information, please see Naming convention String
Key The Key, length of the label is no more than 128byte. It supports letters, numbers, spaces, plus sign, minus sign, underscore, equal sign, period, colon and slash. String
Value The Value, length of the label is no more than 256bytes. It supports letters, numbers, spaces, plus sign, minus sign, underscore, equal sign, period, colon and slash. String

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) otherwise it failed Int

Query Bucket tag

Function description

GET Bucket tagging is used to query the existing Bucket tags under the specified Bucket.

Method prototype

GetBucketTaggingResult getBucketTagging(GetBucketTaggingRequest request)throws CosXmlClientException, CosXmlServiceException;

void getBucketTaggingAsync(GetBucketTaggingRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
GetBucketTaggingRequest getBucketTaggingRequest = new GetBucketTaggingRequest(bucket);
Set<String> headerKeys = new HashSet<>();
headerKeys.add("Host");
getBucketTaggingRequest.setSignParamsAndHeaders(null, headerKeys);
try {
    GetBucketTaggingResult getBucketTaggingResult = cosXmlService.getBucketTagging(getBucketTaggingRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

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)  {
    }
});

Parameter description

Parameter name Description Type
Bucket Query the tag Bucket in BucketName-APPID format. For more information, please see Naming convention String

Return result description

Member variable Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) otherwise it failed Int
Tagging Returns Bucket object Tagging information Tagging

Delete Bucket tag

Function description

DELETE Bucket tagging is used to delete the existing Bucket tag under the specified Bucket.

Method prototype

DeleteBucketTaggingResult deleteBucketTagging(DeleteBucketTaggingRequest request)throws CosXmlClientException, CosXmlServiceException;

void deleteBucketTaggingAsync(DeleteBucketTaggingRequest request, CosXmlResultListener cosXmlResultListener);

Request Sample

String bucket = "examplebucket-1250000000"; 
DeleteBucketTaggingRequest deleteBucketTaggingRequest = new DeleteBucketTaggingRequest(bucket);
Set<String> headerKeys = new HashSet<>();
headerKeys.add("Host");
deleteBucketTaggingRequest.setSignParamsAndHeaders(null, headerKeys);
try {
    DeleteBucketTaggingResult deleteBucketTaggingResult = cosXmlService.deleteBucketTagging(deleteBucketTaggingRequest);
} catch (CosXmlClientException e) {
    e.printStackTrace();
} catch (CosXmlServiceException e) {
    e.printStackTrace();
}

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)  {

    }
});

Parameter description

Parameter name Description Type
Bucket Bucket with the deleted tag is in BucketName-APPID format. For more information, please see Naming convention String

Return result description

Member variable Type Description
HttpCode Int HTTP Code, The operation is successful within the range[200, 300) otherwise it failed