Bucket tag

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

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

void putBucketTaggingAsync(PutBucketTaggingRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("ap-guangzhou") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;          
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; 
  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);

  PutBucketTaggingResult result = cosXml.putBucketTagging(request);

  Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

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 128 bytes, and supports English 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 256 bytes, and supports English 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);

void getBucketTaggingAsync(GetBucketTaggingRequest request,COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("ap-guangzhou") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;         
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; 
  GetBucketTaggingRequest request = new GetBucketTaggingRequest(bucket);   
  GetBucketTaggingResult result = cosXml.getBucketTagging(request);

  Tagging tagging = result.tagging;
  Console.WriteLine(tagging);
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

Parameter description

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

Return result description

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

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

void deleteBucketTaggingAsync(DeleteBucketTaggingRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback);

Request Sample

CosXmlConfig config = new CosXmlConfig.Builder()
  .SetConnectionTimeoutMs(60000)  
  .SetReadWriteTimeoutMs(40000)  
  .IsHttps(true)  
  .SetAppid("1250000000") 
  .SetRegion("ap-guangzhou") 
  .Build();

string secretId = "COS_SECRETID";   
string secretKey = "COS_SECRETKEY"; 
long durationSecond = 600;         
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, 
  secretKey, durationSecond);

CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

try
{
  string bucket = "examplebucket-1250000000"; 
  DeleteBucketTaggingRequest request = new DeleteBucketTaggingRequest(bucket);   
  DeleteBucketTaggingResult result = cosXml.deleteBucketTagging(request);

  Console.WriteLine(result.GetResultInfo());
}
catch (COSXML.CosException.CosClientException clientEx)
{
  Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
  Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

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 Description Type
HttpCode HTTP Code, The operation is successful within the range[200, 300) , otherwise it failed Int