分片拷贝文件
当拷贝一个大于500MB的文件,建议通过oss_upload_part_copy接口来进行拷贝。以下代码实现分片拷贝一个文件
aos_pool_t *p;
oss_request_options_t *options;
char *source_bucket_name = "<您的源bucket名字>";
char *source_object_name = "<您的源object名字>";
char *dest_bucket_name = "<您的目的bucket名字>";
char *dest_object_name = "<您的目的object名字>";
aos_string_t dest_bucket;
aos_string_t dest_object;
aos_string_t upload_id;
aos_table_t *init_headers;
aos_table_t *copy_headers;
aos_table_t *list_part_resp_headers;
aos_table_t *complete_resp_headers
aos_table_t *resp_headers;
aos_status_t *s;
oss_list_upload_part_params_t *list_upload_part_params;
oss_upload_part_copy_params_t *upload_part_copy_params1;
aos_list_t complete_part_list;
oss_list_part_content_t *part_content;
oss_complete_part_content_t *complete_content;
int part1 = 1;
int64_t range_start1 = 0;
int64_t range_end1 = 6000000;//not less than 5MB
int max_ret = 1000;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_options(options);
aos_str_set(&dest_bucket, dest_bucket_name);
aos_str_set(&dest_object, dest_object_name);
init_headers = aos_table_make(p, 0);
s = oss_init_multipart_upload(options, &dest_bucket, &dest_object, init_headers, &upload_id, &resp_headers);
/* 拷贝第一个分片数据 */
upload_part_copy_params1 = oss_create_upload_part_copy_params(p);
aos_str_set(&upload_part_copy_params1->source_bucket, source_bucket_name);
aos_str_set(&upload_part_copy_params1->source_object, source_object_name);
aos_str_set(&upload_part_copy_params1->dest_bucket, dest_bucket_name);
aos_str_set(&upload_part_copy_params1->dest_object, dest_object_name);
aos_str_set(&upload_part_copy_params1->upload_id, upload_id->data);
upload_part_copy_params1->part_num = part1;
upload_part_copy_params1->range_start = range_start1;
upload_part_copy_params1->range_end = range_end1;
copy_headers = aos_table_make(p, 0);
s = oss_upload_part_copy(options, upload_part_copy_params1, copy_headers, &resp_headers);
if (aos_status_is_ok(s)) {
printf("upload part copy succeeded\n");
} else {
printf("upload part copy failed\n");
}
/* 继续拷贝剩余的分片,这里省略*/
…
/* 列出分片 */
list_upload_part_params = oss_create_list_upload_part_params(p);
list_upload_part_params->max_ret = max_ret;
aos_list_init(&complete_part_list);
s = oss_list_upload_part(options, &dest_bucket, &dest_object, &upload_id,
list_upload_part_params, &list_part_resp_headers);
aos_list_for_each_entry(part_content, &list_upload_part_params->part_list, node) {
complete_content = oss_create_complete_part_content(p);
aos_str_set(&complete_content->part_number, part_content->part_number.data);
aos_str_set(&complete_content->etag, part_content->etag.data);
aos_list_add_tail(&complete_content->node, &complete_part_list);
}
/* 完成分片拷贝 */
s = oss_complete_multipart_upload(options, &dest_bucket, &dest_object, &upload_id, &complete_part_list, &complete_resp_headers);
if (aos_status_is_ok(s)) {
printf("complete multipart upload succeeded\n");
} else {
printf("complete multipart upload failed\n");
}
aos_pool_destroy(p);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。