对象存储 OSS6. 下载指定文件
详细解答可以参考官方帮助文档您可以参考下面的代码简单地实现下载指定文件:
aos_pool_t *p; oss_request_options_t *options; aos_status_t *s; aos_table_t *headers; aos_table_t *resp_headers; char *bucket_name = ''; char *object_name = ''; aos_string_t bucket; aos_string_t object; aos_list_t buffer; aos_buf_t *content; char *buf; int64_t len = 0; int64_t size = 0; int64_t pos = 0; aos_pool_create(&p, NULL); /* 创建并初始化options */ options = oss_request_options_create(p); init_options(options); /* 初始化参数 */ aos_str_set(&object, object_name); aos_str_set(&bucket, bucket_name); headers = aos_table_make(p, 1); /* 下载文件到buffer中 */ aos_list_init(&buffer); s = oss_get_object_to_buffer(options, &bucket, &object, headers, &buffer, &resp_headers); /* 判断请求是否成功 */ if (aos_status_is_ok(s)) { printf('get file succeeded\n'); } else { printf('get file failed\n'); } /* 从buffer中将aos_list_t类型的数据转为char*类型的,并计算读到的文件总长度 */ len = aos_buf_list_len(&buffer); buf = aos_pcalloc(p, len + 1); buf[len] = '\0'; aos_list_for_each_entry(content, &buffer, node) { size = aos_buf_size(content); memcpy(buf + pos, content->pos, size); pos += size; } /* 释放资源 */ aos_pool_destroy(p);
注:
关于下载文件更详细的信息,参见下载文件
赞0
踩1