Storage Class
If you have any questions during development, post them on the Issues page of GitHub.
OBS allows you to set storage classes for buckets. The storage class of an object defaults to be that of its residing bucket. There are three types of storage class for buckets, as described in the following table, catering to various storage performance and cost requirements.
Type |
Description |
Value in OBS C SDK |
---|---|---|
OBS Standard |
Features low access latency and high throughput and is applicable to storing frequently-accessed (multiple times per month) hotspot or small objects (< 1 MB) requiring quick response. |
OBS_STORAGE_CLASS_STANDARD |
OBS Infrequent Access |
Is applicable to storing semi-frequently accessed (less than 12 times a year) data requiring quick response. |
OBS_STORAGE_CLASS_STANDARD_IA |
OBS Archive |
Is applicable to archiving rarely-accessed (once a year) data. |
OBS_STORAGE_CLASS_GLACIER |
For more information, see Bucket Storage Classes.
Setting the Storage Class for a Bucket
You can use set_bucket_storage_class_policy to set the bucket storage class. The following table describes the parameters.
Field |
Type |
Mandatory or Optional |
Description |
---|---|---|---|
option |
The context of the bucket. For details, see Configuring option. |
Mandatory |
Bucket parameter |
storage_class_policy |
obs_storage_class |
Mandatory |
Storage class |
handler |
obs_response_handler * |
Mandatory |
Callback function |
callback_data |
void * |
Optional |
Callback data |
Sample code:
static void test_set_bucket_storage_class(char *bucket_name, obs_storage_class storage_class_policy) { 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/intl/en-us/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 }; set_bucket_storage_class_policy(&option, storage_class_policy, &response_handler, &ret_status); if (ret_status == OBS_STATUS_OK) { printf("set bucket storage class successfully. \n"); } else { printf("set bucket storage class failed(%s).\n", obs_get_status_name(ret_status)); } }
Obtaining the Storage Class of a Bucket
You can use get_bucket_storage_class_policy to obtain the bucket storage class. The following table describes the parameters.
Field |
Type |
Mandatory or Optional |
Description |
---|---|---|---|
option |
The context of the bucket. For details, see Configuring option. |
Mandatory |
Bucket parameter |
handler |
obs_get_bucket_storage_class_handler * |
Mandatory |
Callback function |
callback_data |
void * |
Optional |
Callback data |
Sample code:
static void test_get_bucket_storage_class(char *bucket_name) { // Create and initialize option. obs_status ret_status = OBS_STATUS_BUTT; 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/intl/en-us/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_get_bucket_storage_class_handler getBucketStorageResponse = { {0, &response_complete_callback}, &get_bucket_storageclass_handler }; //Obtain the bucket storage class. get_bucket_storage_class_policy(&option, &getBucketStorageResponse, &ret_status); if (OBS_STATUS_OK == ret_status) { printf("get bucket storage class successfully.\n"); } else { printf("get bucket storage class failed(%s).\n", obs_get_status_name(ret_status)); } }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot