-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement multipart with multer (#1033)
* Implement multipart with multer * Update multer to the version where one can poll its stream * Add a multipart example * Add a multipart example to Cargo.toml * Use expect when getting a part's name with multipart * Implement error MultipartFieldMissingName for when multer does not send a part with a name field * Reformat multipart filter with nightly * Make MultipartFieldMissingName private
- Loading branch information
1 parent
08abe44
commit e2f4501
Showing
3 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use futures_util::TryStreamExt; | ||
use warp::multipart::FormData; | ||
use warp::Buf; | ||
use warp::Filter; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// Running curl -F file=@.gitignore 'localhost:3030/' should print [("file", ".gitignore", "\n/target\n**/*.rs.bk\nCargo.lock\n.idea/\nwarp.iml\n")] | ||
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(); | ||
Ok(( | ||
field.name().to_string(), | ||
field.filename().unwrap().to_string(), | ||
contents, | ||
)) | ||
}) | ||
.try_collect() | ||
.await | ||
.unwrap(); | ||
|
||
Ok::<_, warp::Rejection>(format!("{:?}", field_names)) | ||
}); | ||
warp::serve(route).run(([127, 0, 0, 1], 3030)).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters