目标任务:创建出对象obj_name的符号链接obj_link
开发环境:使用官方的OSS C SDK
结果:没有正确创建出符号链接obj_link,创建出的对象名为obj_link%3Fsymlink,且不具备符号链接属性
进一步测试:不做url编码,oss服务器能够正确创建符号链接
直接原因:c sdk在发请求到网络之前对名字做了url编码,obj_link?symlink被编码为了obj_link%3Fsymlink,但是服务器不能正确处理url编码后的请求
进一步分析:
1.Authorization: SignatureValue在sdk中的计算先于url编码,而服务器收到请求后并不会拒绝请求,说明请求接收的模块能够正确处理url编码,在url decode之后再做的Authorization校验;
2.创建出的符号链接名字错误,说明oss模块不具备处理url编码的功能,或者说是负责向oss转发指令的模块不具备识别url编码的能力
3.如果不承认服务器有问题,也可以说是sdk在处理的时候无差别对待object_name不恰当
使用oss c sdk实现创建符号链接关键代码:
const char BUCKET_NAME[] = "xxxxxx";
const char OSS_SYMLINK_TAEGET[] = "x-oss-symlink-target";
aos_status_t *oss_put_symlink(const oss_request_options_t *options,
const aos_string_t *bucket,
const aos_string_t *symlink_object,
const aos_string_t *target_object,
aos_table_t *headers,
aos_table_t **resp_headers)
{
aos_status_t *s = NULL;
aos_http_request_t *req = NULL;
aos_http_response_t *resp = NULL;
aos_table_t *query_params = NULL;
char* tagname = NULL;
headers = aos_table_create_if_null(options, headers, 0);
query_params = aos_table_create_if_null(options, query_params, 0);
tagname = aos_pstrdup(options->pool, target_object);
apr_table_add(headers, OSS_SYMLINK_TAEGET, tagname);
oss_init_object_request(options, bucket, symlink_object, HTTP_PUT,
&req, query_params, headers, NULL, 0, &resp);
s = oss_process_request(options, req, resp);
oss_fill_read_response_header(resp, resp_headers);
return s;
}
void put_object_symlink()
{
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t symlink_object;
aos_string_t target_object;
int is_cname = 0;
aos_table_t *headers = NULL;
aos_table_t *resp_headers = NULL;
oss_request_options_t *options = NULL;
aos_list_t buffer;
aos_buf_t *content = NULL;
char *str = "";
aos_status_t *s = NULL;
char* pbuf = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
headers = aos_table_make(p, 1);
apr_table_set(headers, "x-oss-meta-author", "oss");
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&symlink_object, "obj_link?symlink");// 符号链接名
aos_str_set(&target_object, "obj_name"); // 目标对象名
aos_list_init(&buffer);
content = aos_buf_pack(options->pool, str, strlen(str));
aos_list_add_tail(&content->node, &buffer);
s = oss_put_symlink(options, &bucket, &symlink_object, &target_object, headers, &resp_headers);
if (aos_status_is_ok(s)) {
printf("put object symlink succeeded\n");
}
else {
printf("put object symlink failed\n");
}
aos_pool_destroy(p);
}
const char BUCKET_NAME[] = "xxxxxx";
const char OSS_SYMLINK_TAEGET[] = "x-oss-symlink-target";
const char OSS_REQ_PARAM_SYMLINK[] = "symlink";
aos_status_t *oss_put_symlink(const oss_request_options_t *options,
const aos_string_t *bucket,
const aos_string_t *symlink_object,
const aos_string_t *target_object,
aos_table_t *headers,
aos_table_t **resp_headers)
{
aos_status_t *s = NULL;
aos_http_request_t *req = NULL;
aos_http_response_t *resp = NULL;
aos_table_t *query_params = NULL;
char* targname = NULL;
headers = aos_table_create_if_null(options, headers, 0);
query_params = aos_table_create_if_null(options, query_params, 0);
apr_table_add(query_params, OSS_REQ_PARAM_SYMLINK, ""); // symlink request key without value
targname = aos_pstrdup(options->pool, target_object);
apr_table_add(headers, OSS_SYMLINK_TAEGET, targname);
oss_init_object_request(options, bucket, symlink_object, HTTP_PUT,
&req, query_params, headers, NULL, 0, &resp);
s = oss_process_request(options, req, resp);
oss_fill_read_response_header(resp, resp_headers);
return s;
}
aos_status_t *oss_get_symlink(const oss_request_options_t *options,
const aos_string_t *bucket,
const aos_string_t *symlink_object,
aos_table_t *headers,
aos_table_t **resp_headers)
{
aos_status_t *s = NULL;
aos_http_request_t *req = NULL;
aos_http_response_t *resp = NULL;
aos_table_t *query_params = NULL;
headers = aos_table_create_if_null(options, headers, 0);
query_params = aos_table_create_if_null(options, query_params, 0);
apr_table_add(query_params, OSS_REQ_PARAM_SYMLINK, ""); // symlink request key without value
oss_init_object_request(options, bucket, symlink_object, HTTP_GET,
&req, query_params, headers, NULL, 0, &resp);
s = oss_process_request(options, req, resp);
oss_fill_read_response_header(resp, resp_headers);
return s;
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
void put_object_symlink()
{
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t symlink_object;
aos_string_t target_object;
int is_cname = 0;
aos_table_t *headers = NULL;
aos_table_t *resp_headers = NULL;
oss_request_options_t *options = NULL;
aos_list_t buffer;
aos_buf_t *content = NULL;
char *str = "";
aos_status_t *s = NULL;
char* pbuf = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
headers = aos_table_make(p, 1);
apr_table_set(headers, "x-oss-meta-author", "oss");
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&symlink_object, "obj_link");// 符号链接名
aos_str_set(&target_object, "obj_name"); // 目标对象名
aos_list_init(&buffer);
content = aos_buf_pack(options->pool, str, strlen(str));
aos_list_add_tail(&content->node, &buffer);
s = oss_put_symlink(options, &bucket, &symlink_object, &target_object, headers, &resp_headers);
if (aos_status_is_ok(s)) {
printf("put object symlink succeeded\n");
}
else {
printf("put object symlink failed\n");
}
aos_pool_destroy(p);
}
void get_object_symlink()
{
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t symlink_object;
int is_cname = 0;
aos_table_t *headers = NULL;
aos_table_t *resp_headers = NULL;
oss_request_options_t *options = NULL;
aos_list_t buffer;
aos_buf_t *content = NULL;
char *str = "";
aos_status_t *s = NULL;
char* pLink = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
headers = aos_table_make(p, 1);
apr_table_set(headers, "x-oss-meta-author", "oss");
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&symlink_object, "obj_link");
aos_list_init(&buffer);
content = aos_buf_pack(options->pool, str, strlen(str));
aos_list_add_tail(&content->node, &buffer);
s = oss_get_symlink(options, &bucket, &symlink_object, headers, &resp_headers);
if (aos_status_is_ok(s))
{
printf("get object symlink succeeded\n");
pLink = apr_table_get(resp_headers, "x-oss-symlink-target");
}
else
{
printf("get object symlink failed\n");
}
aos_pool_destroy(p);
}
-------------------------
您的无私奉献精神值得我们学习!向您致敬!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。