Setting Bucket Tags
If you have any questions during development, post them on the Issues page of GitHub.
You can call set_bucket_tagging to set the bucket tags.
Parameter Description
Field |
Type |
Mandatory or Optional |
Description |
---|---|---|---|
options |
The context of the bucket. For details, see Configuring option. |
Mandatory |
Bucket parameter |
tagging_list |
obs_name_value * |
Mandatory |
Tag list |
number |
unsigned int |
Mandatory |
Number of tags |
handler |
obs_response_handler * |
Mandatory |
Callback function |
callback_data |
void * |
Optional |
Callback data |
The following table describes the tag list structure obs_name_value.
Field |
Type |
Description |
---|---|---|
name |
char * |
Tag key |
value |
char * |
Tag value |
Sample Code
static void test_set_bucket_tagging() { obs_status ret_status = OBS_STATUS_BUTT; // Create and initialize option. obs_options option; init_obs_options(&option); option.bucket_options.host_name = "<your-endpoint>"; option.bucket_options.bucket_name = "<Your bucketname>"; // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY. // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/eu/usermanual-ca/ca_01_0003.html. option.bucket_options.access_key = getenv("ACCESS_KEY_ID"); option.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY"); // Set response callback function. obs_response_handler response_handler = { 0, &response_complete_callback }; // Define the bucket tag. char tagKey[][OBS_COMMON_LEN_256] = {{"k1"},{"k2"},{"k3"},{"k4"},{"k5"},{"k6"},{"k7"},{"k8"},{"k9"},{"k10"}}; char tagValue[][OBS_COMMON_LEN_256] = {{"v1"},{"v2"},{"v3"},{"v4"},{"v5"},{"v6"},{"v7"},{"v8"},{"v9"},{"v10"}}; obs_name_value tagginglist[10] = {0}; int i=0; for(;i<10;i++) { tagginglist[i].name = tagKey[i]; tagginglist[i].value = tagValue[i]; } // Set bucket tags. set_bucket_tagging(&option, tagginglist, 8, &response_handler, &ret_status); if (OBS_STATUS_OK == ret_status) { printf("set bucket tagging successfully. \n"); } else { printf("set bucket tagging failed(%s).\n", obs_get_status_name(ret_status)); } }
- A bucket can have up to 10 tags.
- The key and value of a tag can be composed of Unicode characters.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.