As this answer explains, it's possible to use Body::wrap_stream(read_stream)
to POST the contents of a file without first reading the entire contents into memory.
How can we do the same thing as part of a reqwest::multipart::Form
? The following code fails with the error the trait `From<&mut dyn Stream<Item = std::result::Result<Vec<u8>, std::io::Error>>>` is not implemented for `Body`
.
let metadata_json = "{ \"file_owner\": \"bob smith\" }";
let metadata_part = reqwest::multipart::Part::text(metadata_json);
let read_stream : Stream<Item = std::io::Result<Vec<u8>> = my_file_stream;
let stream_part = reqwest::multipart::Part::stream(read_stream);
let multipart_form = reqwest::multipart::Form::new()
.part("metadata", metadata_part)
.part("file", stream_part);
I tried supplying an implementation of From
that just calls Body::wrap_stream
but it's forbidden since neither From
nor Body
is defined in my own code.