This document provides an overview of APIs and SDK code samples related to bucket tagging.
Setting Bucket Tag
Feature description
This API (PUT Bucket tagging) is used to set a tag for an existing bucket.
Method prototype
public Guzzle\Service\Resource\Model PutBucketTagging(array $args = array());
Sample request
try {
$result = $cosClient->putBucketTagging(array(
'Bucket' => 'examplebucket-1250000000',
'TagSet' => array(
array('Key'=>'key1',
'Value'=>'value1',
),
array('Key'=>'key2',
'Value'=>'value2',
),
),
));
print_r($result);
} catch (\Exception $e) {
echo "$e\n";
}
Parameter description
Parameter Name |
Description |
Type |
Bucket |
Bucket for which to set a tag in the format of BucketName-APPID . For more information, please see Naming Convention |
String |
Key |
Tag key |
String |
Value |
Tag value |
String |
Querying Bucket Tag
Feature description
This API (GET Bucket tagging) is used to query the existing tags of a specified bucket.
Method prototype
public Guzzle\Service\Resource\Model GetBucketTagging(array $args = array());
Sample request
try {
$result = $cosClient->getBucketTagging(array(
'Bucket' => 'examplebucket-1250000000',
));
print_r($result);
} catch (\Exception $e) {
echo($e);
}
Parameter description
Parameter Name |
Description |
Type |
Bucket |
Bucket for which to query a tag in the format of BucketName-APPID . For more information, please see Naming Convention |
String |
Sample return result
GuzzleHttp\Command\Result Object
(
[TagSet] => Array
(
[0] => Array
(
[Key] => key1
[Value] => value1
)
[1] => Array
(
[Key] => key2
[Value] => value2
)
)
[RequestId] => NWRmMWVkMjFfMjJiMjU4NjRfNWQ3X2EwMWVj****
)
Returned result description
Member Variable |
Description |
Type |
Key |
Tag key |
String |
Value |
Tag value |
String |
Deleting Bucket Tag
Feature description
This API (DELETE Bucket tagging) is used to delete an existing tag of a specified bucket.
Method prototype
public Guzzle\Service\Resource\Model DeleteBucketTagging(array $args = array());
Sample request
try {
$result = $cosClient->deleteBucketTagging(array(
'Bucket' => 'examplebucket-1250000000',
);
print_r($result);
} catch (\Exception $e) {
echo($e);
}
Parameter description
Parameter Name |
Description |
Type |
Bucket |
Bucket for which to delete a tag in the format of BucketName-APPID . For more information, please see Naming Convention |
String |
Was this page helpful?