Diese Seite ist in Ihrer lokalen Sprache noch nicht verfügbar. Wir arbeiten daran, weitere Sprachversionen hinzuzufügen. Vielen Dank für Ihre Unterstützung.

On this page

Show all

URL for Uploading an Object

Updated on 2023-11-09 GMT+08:00
NOTICE:

If you have any questions during development, post them on the Issues page of GitHub.

static void test_put_object_auth()
{
    // 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");
    temp_auth_configure tempauth;
        
    tempAuthResult  ptrResult;
    memset_s(&ptrResult,sizeof(tempAuthResult),0,sizeof(tempAuthResult));
    // Callback data
    tempauth.callback_data = (void *)(&ptrResult);  
    // Validity period
    tempauth.expires = 10;
    // Callback function returns and generates the temporary URL.
    tempauth.temp_auth_callback = &tempAuthCallBack_getResult;
    option.temp_auth = &tempauth;
    // Initialize the put_properties structure.
    obs_put_properties put_properties;
    init_put_properties(&put_properties);
    // Callback data
    put_file_object_callback_data data;
    memset(&data, 0, sizeof(put_file_object_callback_data));
    data.infile = 0;
    data.noStatus = 1;
    content_length = read_bytes_from_file(file_name, &data);
    // Set response callback function.
    obs_put_object_handler putobjectHandler =
    {
    { &response_properties_callback,
          &response_complete_callback },
        &put_buffer_object_data_callback
     };
    // Upload data streams.
    put_object(&option,key,content_length,&put_properties,0,&putobjectHandler,&data);
    if (OBS_STATUS_OK == data.ret_status) {printf("the temporary signature url of put object from file generated successfully. The result is recorded in the tmpAuthUrl.txt file. \n");
    }
    else
    {
         printf("the temporary signature url of put object from file generation faied(%s).\n", obs_get_status_name(data.ret_status));
    }
}

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback