Post a file with data streaming
This commit is contained in:
+19
-10
@@ -51,20 +51,29 @@ RequestPtr RequestBuilder::operator()() {
|
||||
return request;
|
||||
}
|
||||
|
||||
RequestBuilder& RequestBuilder::File(const std::string& name,
|
||||
const Path& path,
|
||||
const std::string& media_type) {
|
||||
assert(!name.empty());
|
||||
form_parts_.push_back(FormPart::NewFile(name, path, media_type));
|
||||
RequestBuilder& RequestBuilder::File(const Path& path, bool infer_media_type,
|
||||
std::size_t chunk_size) {
|
||||
body_.reset(new FileBody{ path, chunk_size });
|
||||
|
||||
if (infer_media_type) {
|
||||
media_type_ = media_types::FromExtension(path.extension().string());
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
RequestBuilder& RequestBuilder::Form(const std::string& name,
|
||||
std::string&& data,
|
||||
const std::string& media_type) {
|
||||
RequestBuilder& RequestBuilder::FormFile(const std::string& name,
|
||||
const Path& path,
|
||||
const std::string& media_type) {
|
||||
assert(!name.empty());
|
||||
form_parts_.push_back(FormPart::New(name, std::move(data), media_type));
|
||||
return *this;
|
||||
return Form(FormPart::NewFile(name, path, media_type));
|
||||
}
|
||||
|
||||
RequestBuilder& RequestBuilder::FormData(const std::string& name,
|
||||
std::string&& data,
|
||||
const std::string& media_type) {
|
||||
assert(!name.empty());
|
||||
return Form(FormPart::New(name, std::move(data), media_type));
|
||||
}
|
||||
|
||||
RequestBuilder& RequestBuilder::Auth(const std::string& type,
|
||||
|
||||
+11
-5
@@ -95,17 +95,23 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Add a file to upload.
|
||||
RequestBuilder& File(const std::string& name, const Path& path,
|
||||
const std::string& media_type = "");
|
||||
// Use the file content as body.
|
||||
RequestBuilder& File(const Path& path, bool infer_media_type = true,
|
||||
std::size_t chunk_size = 1024);
|
||||
|
||||
// Add a form part.
|
||||
RequestBuilder& Form(FormPartPtr part) {
|
||||
form_parts_.push_back(part);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RequestBuilder& Form(const std::string& name, std::string&& data,
|
||||
const std::string& media_type = "");
|
||||
// Add a form part of file.
|
||||
RequestBuilder& FormFile(const std::string& name, const Path& path,
|
||||
const std::string& media_type = "");
|
||||
|
||||
// Add a form part of string data.
|
||||
RequestBuilder& FormData(const std::string& name, std::string&& data,
|
||||
const std::string& media_type = "");
|
||||
|
||||
RequestBuilder& Header(const std::string& key, const std::string& value) {
|
||||
headers_.push_back(key);
|
||||
|
||||
Reference in New Issue
Block a user