Obtaining a Versioning Object
If you have any questions during development, post them on the Issues page of GitHub.
You can call get_object to pass the version ID (obs_object_info .version_id) to obtain a versioning object. Sample code is as follows:
static void test_get_object_version() { // Create and initialize the object, and specify the object version through obs_object_info.key. obs_object_info object_info; memset(&object_info, 0, sizeof(obs_object_info)); object_info.key =key; object_info.version_id = versionid; // 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"); // Create and Initialize callback data. char *file_name = "./test"; get_object_callback_data data; data.ret_status = OBS_STATUS_BUTT; data.outfile = NULL; data.outfile = write_to_file(file_name); // Set response callback function. obs_get_object_handler getobjectHandler = { { &response_properties_callback, &get_object_complete_callback}, &get_object_data_callback }; // Obtain a versioning object. get_object(&option,&object_info,0,0,&getobjectHandler,&data); 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)); } fclose(data.outfile); }
If the version ID is null, the object of the latest version will be downloaded by default.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.