Bucket tag

Last updated: 2020-03-20 09:25:10

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

When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

  1. Instantiate QCloudPutBucketTaggingRequest
  2. Call the PutBucketTagging method in the QCloudCOSXMLService object to make the request.
  3. Get the specific content from the outputObject in the finishBlock of the callback.

Request Sample

QCloudPutBucketTaggingRequest *putReq = [QCloudPutBucketTaggingRequest new];
putReq.bucket = @"examplebucket-1250000000";

QCloudBucketTagging *taggings = [QCloudBucketTagging new];
QCloudBucketTag *tag1 = [QCloudBucketTag new];
QCloudBucketTagSet *tagSet = [QCloudBucketTagSet new];
taggings.tagSet = tagSet;
tag1.key = @"age";
tag1.value = @"20";
QCloudBucketTag *tag2 = [QCloudBucketTag new];
tag2.key = @"name";
tag2.value = @"karis";
tagSet.tag = @[tag1,tag2];
putReq.taggings = taggings;

[putReq setFinishBlock:^(id outputObject, NSError *error) {

}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketTagging:putReq];

Swift code example:

let req = QCloudPutBucketTaggingRequest.init();
req.bucket = "examplebucket-1250000000";
let taggings = QCloudBucketTagging.init();
let tagSet = QCloudBucketTagSet.init();
taggings.tagSet = tagSet;
let tag1 = QCloudBucketTag.init();
tag1.key = "age";
tag1.value = "20";

let tag2 = QCloudBucketTag.init();
tag2.key = "name";
tag2.value = "karis";
tagSet.tag = [tag1,tag2];
req.taggings = taggings;
req.finishBlock = {(result,error) in

    if error != nil{
        print(error!);
    }else{
        print( result!);
    }
}
QCloudCOSXMLService.defaultCOSXML().putBucketTagging(req);

Parameter description

QCloudPutBucketTaggingRequest request parameter description

Parameter name Description Type Required/Optional
Bucket Bucket is tagged in BucketName-APPID format. For more information, please see Naming convention NSString * Yes
Taggings Label collection QCloudBucketTagging * Yes

QCloudBucketTagging parameter description

Parameter name Description Type Required/Optional
TagSet Collection of tag QCloudBucketTagSet * Yes

QCloudBucketTagSet parameter description

Parameter name Description Type Required/Optional
tag Tag collection, supporting up to 10 tags NSArray < QCloudBucketTag * > * Yes

QCloudBucketTag parameter description

Parameter name Description Type Required/Optional
Key Tag key NSString * Yes
Value Tag value NSString * Yes

Returns the error code description

When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.

Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.

  • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
  • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
  • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.

Query Bucket tag

Function description

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

Method prototype

When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

  1. Instantiate QCloudGetBucketTaggingRequest
  2. Call the GetBucketTagging method in the QCloudCOSXMLService object to make the request.
  3. Get the specific content from the result in the finishBlock of the callback.

Request Sample

QCloudGetBucketTaggingRequest *getReq = [QCloudGetBucketTaggingRequest new];
       getReq.bucket = @"examplebucket-1250000000";
       [getReq setFinishBlock:^(QCloudBucketTagging * result, NSError * error) {
       }];
       [[QCloudCOSXMLService defaultCOSXML] GetBucketTagging:getReq];

Swift code example:

let req = QCloudGetBucketTaggingRequest.init();
req.bucket = "examplebucket-1250000000";
req.setFinish { (result, error) in

    if error != nil{
        print(error!);
    }else{
        print( result!);
    }
};
QCloudCOSXMLService.defaultCOSXML().getBucketTagging(req);

Parameter description

QCloudGetBucketTaggingRequest request parameter description

Parameter name Description Type Required/Optional
Bucket Query the tag Bucket in BucketName-APPID format. For more information, please see Naming convention NSString * Yes

Return result description

QCloudBucketTagging parameter description

Parameter name Description Type
TagSet Collection of tags QCloudBucketTagSet *

Returns the error code description

When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.

Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.

  • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
  • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
  • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.

Delete Bucket tag

Function description

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

Method prototype

When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

  1. Instantiate QCloudDeleteBucketTaggingRequest
  2. Call the DeleteBucketTagging method in the QCloudCOSXMLService object to make the request.
  3. Get the specific content from the outputObject in the finishBlock of the callback.

Request Sample

QCloudDeleteBucketTaggingRequest *delReq = [QCloudDeleteBucketTaggingRequest new];
delReq.bucket =  @"examplebucket-1250000000";
[delReq setFinishBlock:^(id outputObject, NSError *error) {

}];
[[QCloudCOSXMLService defaultCOSXML] DeleteBucketTagging:delReq];

Swift code example:

let req = QCloudDeleteBucketTaggingRequest.init();
req.bucket = "examplebucket-1250000000";
req.finishBlock =  { (result, error) in

    if error != nil{
        print(error!);
    }else{
        print( result!);
    }
};
QCloudCOSXMLService.defaultCOSXML().deleteBucketTagging(req);

Parameter description

QCloudDeleteBucketTaggingRequest request parameter description

Parameter name Description Type Required/Optional
Bucket Bucket with the deleted tag is in BucketName-APPID format. For more information, please see Naming convention NSString * Yes

Returns the error code description

When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.

Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.

  • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
  • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
  • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.