Skip to content

Commit

Permalink
Add content length to async_impl::multipart file streams (#2459)
Browse files Browse the repository at this point in the history
Co-authored-by: I-Al-Istannen <[email protected]>
  • Loading branch information
Mr-Pine and I-Al-Istannen authored Oct 27, 2024
1 parent d99e90d commit 598f857
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/async_impl/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ impl Part {
let ext = path.extension().and_then(|ext| ext.to_str()).unwrap_or("");
let mime = mime_guess::from_ext(ext).first_or_octet_stream();
let file = File::open(path).await?;
let field = Part::stream(file).mime(mime);
let len = file.metadata().await.map(|m| m.len()).ok();
let field = match len {
Some(len) => Part::stream_with_length(file, len),
None => Part::stream(file)
}.mime(mime);

Ok(if let Some(file_name) = file_name {
field.file_name(file_name)
Expand Down

0 comments on commit 598f857

Please sign in to comment.