Downloading an Archive Object
If you have any questions during development, post them on the Issues page of GitHub.
Before you can download an Archive object, you must restore it. Archive objects can be restored in either of the following ways.
Option |
Description |
Value in OBS C SDK |
---|---|---|
Expedited restore |
Data can be restored within 1 to 5 minutes. |
OBS_TIER_EXPEDITED |
Standard restore |
Data can be restored within 3 to 5 hours. This is the default option. |
OBS_TIER_STANDARD |
To prolong the validity period of the Archive data restored, you can repeatedly restore the Archive data, but you will be billed for each restore. After a second restore, the validity period of Standard object copies will be prolonged, and you need to pay for storing these copies during the prolonged period.
You can call restore_object to restore an Archive object. Sample code:
Parameter Description
Field |
Type |
Mandatory or Optional |
Description |
---|---|---|---|
option |
The context of the bucket. For details, see Configuring option. |
Mandatory |
Bucket parameter |
object_info |
obs_object_info * |
Mandatory |
Object name and version number. For non-multi-version objects, set version to 0. |
days |
char * |
Mandatory |
Retention period of the restored object |
tier |
obs_tier |
Optional |
Restore options: obs_tier.OBS_TIER_EXPEDITED or obs_tier.OBS_TIER_STANDARD |
handler |
obs_response_handler * |
Mandatory |
Callback function |
callback_data |
void * |
Optional |
Callback data |
static void test_restore_object() { // Define object information. obs_object_info object_info; memset(&object_info, 0, sizeof(obs_object_info)); object_info.key = "<object key>"; object_info.version_id = "<object version ID>"; 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 handler = { &response_properties_callback, &response_complete_callback }; // Restore the object. obs_tier tier = OBS_TIER_EXPEDITED; restore_object(&option, &object_info, "<stored time>",tier,&handler, &ret_status); if (OBS_STATUS_OK == ret_status) { printf("restore object successfully. \n"); } else { printf("restore object faied(%s).\n", obs_get_status_name(ret_status)); return; } // Download object callback data. get_object_callback_data data; data.ret_status = OBS_STATUS_BUTT; data.outfile = write_to_file("<file path>"); // Set response callback function. obs_get_object_handler getobjectHandler = { { &response_properties_callback, &get_object_complete_callback}, &get_object_data_callback }; // Download an object. get_object(&option,&object_info, 0,0,&getobjectHandler,&data); fclose(data.outfile); if (OBS_STATUS_OK == data.ret_status) { printf("get object successfully. \n"); } else { printf("get object faied(%s).\n", obs_get_status_name(data.ret_status)); } }
- The object specified in object_info.key must be in the OBS Archive storage class. Otherwise, an error will be reported when you call this API.
- <Retention period of the restored object> indicates how long (1 to 30 days) the restored object will be retained.
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