1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

add multipart guide section

This commit is contained in:
Nikolay Kim
2017-12-19 10:10:03 -08:00
parent e3f9345420
commit 2e790dfcc6
3 changed files with 43 additions and 8 deletions

View File

@ -15,15 +15,15 @@ fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>>
// get multipart stream and iterate over multipart items
Box::new(
req.multipart()
req.multipart() // <- get multipart stream for current request
.map_err(Error::from)
.and_then(|item| {
// Multipart stream is a stream of Fields and nested Multiparts
.and_then(|item| { // <- iterate over multipart items
match item {
// Handle multipart Field
multipart::MultipartItem::Field(field) => {
println!("==== FIELD ==== {:?}", field);
// Read field's stream
// Field in turn is stream of *Bytes* object
Either::A(
field.map_err(Error::from)
.map(|chunk| {
@ -32,12 +32,12 @@ fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>>
.fold((), |_, _| result::<_, Error>(Ok(()))))
},
multipart::MultipartItem::Nested(mp) => {
// Do nothing for nested multipart stream
// Or item could be nested Multipart stream
Either::B(result(Ok(())))
}
}
})
// wait until stream finish
// wait until stream finishes
.fold((), |_, _| result::<_, Error>(Ok(())))
.map(|_| httpcodes::HTTPOk.response())
)