Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parameter for async_upload_chunked #406

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,15 @@ class coro_http_client {
template <typename S, typename String>
async_simple::coro::Lazy<resp_data> async_upload_chunked(
S uri, http_method method, String filename,
req_content_type content_type = req_content_type::text,
std::unordered_map<std::string, std::string> headers = {}) {
std::shared_ptr<int> guard(nullptr, [this](auto) {
if (!req_headers_.empty()) {
req_headers_.clear();
}
});

req_context<> ctx{req_content_type::text};
req_context<> ctx{content_type};
resp_data data{};
auto [ok, u] = handle_uri(data, uri);
if (!ok) {
Expand Down
3 changes: 2 additions & 1 deletion lang/coro_http_client_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ async_simple::coro::Lazy<resp_data> async_trace(std::string uri);
template <typename S, typename String>
async_simple::coro::Lazy<resp_data> async_upload_chunked(
S uri, http_method method, String filename,
req_content_type content_type = req_content_type::text,
std::unordered_map<std::string, std::string> headers = {});
```
method 一般是POST 或者PUT,filename 是带路径的文件名,headers 是请求头,这些参数填好之后,coro_http_client 会自动将文件分块上传到服务器,直到全部上传完成之后才co_return,中间上传出错也会返回。
method 一般是POST 或者PUT,filename 是带路径的文件名,content_type 文件的类型,headers 是请求头,这些参数填好之后,coro_http_client 会自动将文件分块上传到服务器,直到全部上传完成之后才co_return,中间上传出错也会返回。

chunked 每块的大小默认为1MB,如果希望修改分块大小可以通过set_max_single_part_size 接口去设置大小,或者通过config 里面的max_single_part_size配置项去设置。

Expand Down
Loading