Skip to content

Commit

Permalink
Merge pull request #30 from aliyun/fix-resumable-upload
Browse files Browse the repository at this point in the history
fix resumable upload
  • Loading branch information
baiyubin2020 authored Apr 23, 2017
2 parents 3e65883 + d62fe8d commit 703c58f
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 26 deletions.
1 change: 0 additions & 1 deletion oss_c_sdk/oss_define.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const char OSS_COPY_SOURCE[] = "x-oss-copy-source";
const char OSS_COPY_SOURCE_RANGE[] = "x-oss-copy-source-range";
const char OSS_SECURITY_TOKEN[] = "security-token";
const char OSS_STS_SECURITY_TOKEN[] = "x-oss-security-token";
const char OSS_REPLACE_OBJECT_META[] = "x-oss-replace-object-meta";
const char OSS_OBJECT_TYPE[] = "x-oss-object-type";
const char OSS_NEXT_APPEND_POSITION[] = "x-oss-next-append-position";
const char OSS_HASH_CRC64_ECMA[] = "x-oss-hash-crc64ecma";
Expand Down
1 change: 0 additions & 1 deletion oss_c_sdk/oss_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ extern const char OSS_COPY_SOURCE[];
extern const char OSS_COPY_SOURCE_RANGE[];
extern const char OSS_SECURITY_TOKEN[];
extern const char OSS_STS_SECURITY_TOKEN[];
extern const char OSS_REPLACE_OBJECT_META[];
extern const char OSS_OBJECT_TYPE[];
extern const char OSS_NEXT_APPEND_POSITION[];
extern const char OSS_HASH_CRC64_ECMA[];
Expand Down
5 changes: 2 additions & 3 deletions oss_c_sdk/oss_multipart.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ aos_status_t *oss_init_multipart_upload(const oss_request_options_t *options,

//init headers
headers = aos_table_create_if_null(options, headers, 1);
oss_set_multipart_content_type(headers);
set_content_type(NULL, object->data, headers);

oss_init_object_request(options, bucket, object, HTTP_POST,
&req, query_params, headers, NULL, 0, &resp);
Expand Down Expand Up @@ -194,8 +194,7 @@ aos_status_t *oss_do_complete_multipart_upload(const oss_request_options_t *opti

//init headers
headers = aos_table_create_if_null(options, headers, 1);
oss_set_multipart_content_type(headers);
apr_table_add(headers, OSS_REPLACE_OBJECT_META, OSS_YES);
apr_table_set(headers, OSS_CONTENT_TYPE, OSS_MULTIPART_CONTENT_TYPE);

oss_init_object_request(options, bucket, object, HTTP_POST,
&req, query_params, headers, NULL, 0, &resp);
Expand Down
8 changes: 0 additions & 8 deletions oss_c_sdk/oss_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,6 @@ oss_list_live_channel_params_t *oss_create_list_live_channel_params(aos_pool_t *
return params;
}

void oss_set_multipart_content_type(aos_table_t *headers)
{
const char *content_type;
content_type = (char*)(apr_table_get(headers, OSS_CONTENT_TYPE));
content_type = content_type == NULL ? OSS_MULTIPART_CONTENT_TYPE : content_type;
apr_table_set(headers, OSS_CONTENT_TYPE, content_type);
}

const char *get_oss_acl_str(oss_acl_e oss_acl)
{
switch (oss_acl) {
Expand Down
6 changes: 0 additions & 6 deletions oss_c_sdk/oss_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,6 @@ oss_upload_part_copy_params_t *oss_create_upload_part_copy_params(aos_pool_t *p)
**/
oss_upload_file_t *oss_create_upload_file(aos_pool_t *p);

/**
* @brief get content-type for HTTP_POST request
* @return content-type for HTTP_POST request
**/
void oss_set_multipart_content_type(aos_table_t *headers);

/**
* @brief create lifecycle rule content
* @return lifecycle rule content
Expand Down
2 changes: 1 addition & 1 deletion oss_c_sdk_test/test_oss_bucket.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void test_list_object(CuTest *tc)
params = oss_create_list_object_params(p);
params->max_ret = 1;
params->truncated = 0;
aos_str_set(&params->prefix, "oss_test");
aos_str_set(&params->prefix, "oss_test_object");
aos_str_set(&bucket, TEST_BUCKET_NAME);
s = oss_list_object(options, &bucket, params, &resp_headers);
CuAssertIntEquals(tc, 200, s->code);
Expand Down
10 changes: 5 additions & 5 deletions oss_c_sdk_test/test_oss_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void test_resize_image(CuTest *tc) {
get_iamge_info(tc, &image_info);
CuAssertIntEquals(tc, 100, image_info.height);
CuAssertIntEquals(tc, 100, image_info.width);
CuAssertIntEquals(tc, 3587, image_info.size);
CuAssertIntEquals(tc, 3267, image_info.size);
CuAssertStrEquals(tc, "jpg", image_info.format);

printf("test_resize_image ok\n");
Expand Down Expand Up @@ -171,7 +171,7 @@ void test_crop_image(CuTest *tc) {
get_iamge_info(tc, &image_info);
CuAssertIntEquals(tc, 100, image_info.height);
CuAssertIntEquals(tc, 100, image_info.width);
CuAssertIntEquals(tc, 2281, image_info.size);
CuAssertIntEquals(tc, 1969, image_info.size);
CuAssertStrEquals(tc, "jpg", image_info.format);

printf("test_crop_image ok\n");
Expand Down Expand Up @@ -221,7 +221,7 @@ void test_rotate_image(CuTest *tc) {
get_iamge_info(tc, &image_info);
CuAssertIntEquals(tc, 400, image_info.height);
CuAssertIntEquals(tc, 267, image_info.width);
CuAssertIntEquals(tc, 21509, image_info.size);
CuAssertIntEquals(tc, 20998, image_info.size);
CuAssertStrEquals(tc, "jpg", image_info.format);

printf("test_rotate_image ok\n");
Expand Down Expand Up @@ -271,7 +271,7 @@ void test_sharpen_image(CuTest *tc) {
get_iamge_info(tc, &image_info);
CuAssertIntEquals(tc, 267, image_info.height);
CuAssertIntEquals(tc, 400, image_info.width);
CuAssertIntEquals(tc, 24183, image_info.size);
CuAssertIntEquals(tc, 23015, image_info.size);
CuAssertStrEquals(tc, "jpg", image_info.format);

printf("test_sharpen_image ok\n");
Expand Down Expand Up @@ -321,7 +321,7 @@ void test_watermark_image(CuTest *tc) {
get_iamge_info(tc, &image_info);
CuAssertIntEquals(tc, 267, image_info.height);
CuAssertIntEquals(tc, 400, image_info.width);
CuAssertIntEquals(tc, 26953, image_info.size);
CuAssertIntEquals(tc, 26369, image_info.size);
CuAssertStrEquals(tc, "jpg", image_info.format);

printf("test_watermark_image ok\n");
Expand Down
2 changes: 1 addition & 1 deletion oss_c_sdk_test/test_oss_multipart.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void test_multipart_upload(CuTest *tc)
int part_num = 1;
int part_num1 = 2;
char *expect_part_num_marker = "1";
char *content_type_for_complete = "video/MP2T";
char *content_type_for_complete = "application/octet-stream";
char *actual_content_type = NULL;

aos_pool_create(&p, NULL);
Expand Down
53 changes: 53 additions & 0 deletions oss_c_sdk_test/test_oss_resumable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,58 @@ void test_resumable_upload_progress_with_checkpoint(CuTest *tc)
printf("test_resumable_upload_progress_with_checkpoint ok\n");
}

void test_resumable_upload_content_type(CuTest *tc)
{
aos_pool_t *p = NULL;
char *object_name = "test_resumable_upload_content_type.ts";
aos_string_t bucket;
aos_string_t object;
aos_string_t filename;
aos_status_t *s = NULL;
int is_cname = 0;
aos_table_t *headers = NULL;
aos_table_t *resp_headers = NULL;
aos_list_t resp_body;
oss_request_options_t *options = NULL;
oss_resumable_clt_params_t *clt_params;
int64_t content_length = 0;
char *content_type = NULL;

aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_test_request_options(options, is_cname);
headers = aos_table_make(p, 0);
aos_str_set(&bucket, TEST_BUCKET_NAME);
aos_str_set(&object, object_name);
aos_list_init(&resp_body);
aos_str_set(&filename, test_local_file);

// upload object
clt_params = oss_create_resumable_clt_params_content(p, 1024 * 100, 3, AOS_TRUE, NULL);
s = oss_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
clt_params, NULL, &resp_headers, &resp_body);
CuAssertIntEquals(tc, 200, s->code);

aos_pool_destroy(p);

// head object
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_test_request_options(options, is_cname);
s = oss_head_object(options, &bucket, &object, NULL, &resp_headers);
CuAssertIntEquals(tc, 200, s->code);

content_length = atol((char*)apr_table_get(resp_headers, OSS_CONTENT_LENGTH));
CuAssertTrue(tc, content_length == get_file_size(test_local_file));

content_type = (char*)(apr_table_get(resp_headers, OSS_CONTENT_TYPE));
CuAssertStrEquals(tc, "video/MP2T", content_type);

aos_pool_destroy(p);

printf("test_resumable_upload_content_type ok\n");
}

CuSuite *test_oss_resumable()
{
CuSuite* suite = CuSuiteNew();
Expand Down Expand Up @@ -1377,6 +1429,7 @@ CuSuite *test_oss_resumable()
SUITE_ADD_TEST(suite, test_resumable_upload_progress_without_checkpoint);
SUITE_ADD_TEST(suite, test_resumable_upload_callback_with_checkpoint);
SUITE_ADD_TEST(suite, test_resumable_upload_progress_with_checkpoint);
SUITE_ADD_TEST(suite, test_resumable_upload_content_type);
SUITE_ADD_TEST(suite, test_resumable_cleanup);

return suite;
Expand Down

0 comments on commit 703c58f

Please sign in to comment.