-
There are example of how to use the blocking client to upload a file with multipart form, however there is no how to's for the async client. After looking around the internet I came up with this solution : let file_handle = File::open(file_path)
.await
.expect(format!("Failed to open image at {}", file_path).as_str());
let bytes_stream = FramedRead::new(file_handle, BytesCodec::new());
let form = multipart::Form::new().part(
"image",
multipart::Part::stream(reqwest::Body::wrap_stream(bytes_stream))
.file_name(filename)
.mime_str(mime)
.expect("Invalid mime for creating an image"),
);
reqwest.post("...").multipart(form).send().await.expect("Failed to execute request") However using a request bin I see that the body is empty. |
Beta Was this translation helpful? Give feedback.
Answered by
leo91000
Jun 14, 2022
Replies: 1 comment
-
I found my error, I added manually the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
leo91000
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found my error, I added manually the
Content-Type
header, so it was i ncompatible with the multipart header. As a result the multipart request was invalid.