From 598f8574cb428bb03b487e0abfd8169a594dd2db Mon Sep 17 00:00:00 2001 From: "Mr. Pine" Date: Sun, 27 Oct 2024 21:38:51 +0100 Subject: [PATCH] Add content length to async_impl::multipart file streams (#2459) Co-authored-by: I-Al-Istannen --- src/async_impl/multipart.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/async_impl/multipart.rs b/src/async_impl/multipart.rs index 525876dde..ac4b8b981 100644 --- a/src/async_impl/multipart.rs +++ b/src/async_impl/multipart.rs @@ -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)