Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multipart example for bigger files #1044

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions examples/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ async fn main() {
let route = warp::multipart::form().and_then(|form: FormData| async move {
let field_names: Vec<_> = form
.and_then(|mut field| async move {
let contents =
String::from_utf8_lossy(field.data().await.unwrap().unwrap().chunk())
.to_string();
let mut bytes: Vec<u8> = Vec::new();

// field.data() only returns a piece of the content, you should call over it until it replies None
while let Some(content) = field.data().await {
let content = content.unwrap();
let chunk: &[u8] = content.chunk();
bytes.extend_from_slice(chunk);
}
Ok((
field.name().to_string(),
field.filename().unwrap().to_string(),
contents,
String::from_utf8_lossy(&*bytes).to_string(),
))
})
.try_collect()
Expand Down