更新时间:2023-11-08 GMT+08:00
分享

生成删除对象的URL

开发过程中,您有任何问题可以在github上提交issue,或者在华为云对象存储服务论坛中发帖求助。

static void test_delete_object_auth()
{
    obs_status ret_status = OBS_STATUS_BUTT;
    // 创建并初始化option
    obs_options option;
    init_obs_options(&option);
    option.bucket_options.host_name = "<your-endpoint>";
    option.bucket_options.bucket_name = "<Your bucketname>";

    // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量ACCESS_KEY_ID和SECRET_ACCESS_KEY。
    // 您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/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));
    //回调数据
    tempauth.callback_data = (void *)(&ptrResult);  
    // 有效时间    
    tempauth.expires = 10;
    // 回调函数 返回生成的临时URL
    tempauth.temp_auth_callback = &tempAuthCallBack_getResult;
    option.temp_auth = &tempauth;
    // 对象的信息
    obs_object_info object_info;
    memset(&object_info,0,sizeof(obs_object_info));
    object_info.key = key;
    // 回调函数赋值    
    obs_response_handler resqonseHandler =
    { 
    &response_properties_callback,
        &response_complete_callback 
    };
    // 删除对象
    delete_object(&option,&object_info,&resqonseHandler, &ret_status);
    if (OBS_STATUS_OK == ret_status) 
    {printf("the temporary signature url of delete object generated successfully. The result is recorded in the tmpAuthUrl.txt file. \n");
    }
    else
    {
        printf("the temporary signature url of delete object generation failed(%s).\n", obs_get_status_name(ret_status));
    }
}

分享:

    相关文档

    相关产品