diff --git a/examples/simple.rs b/examples/simple.rs index 5053132..13f412d 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -11,8 +11,8 @@ impl FormData for UploadedContent { type Item = (); type Error = Error; - fn form(_: &HttpRequest) -> Form { - Form::new() + fn form(_: &HttpRequest) -> Result, Self::Error> { + Ok(Form::new() .field("Hey", Field::text()) .field( "Hi", @@ -29,7 +29,7 @@ impl FormData for UploadedContent { } Ok(()) as Result<(), Error> })), - ) + )) } fn extract(value: Value) -> Result diff --git a/examples/upload.rs b/examples/upload.rs index cf98ad5..14230f4 100644 --- a/examples/upload.rs +++ b/examples/upload.rs @@ -61,11 +61,11 @@ impl FormData for UploadedContent { type Item = PathBuf; type Error = Errors; - fn form(req: &HttpRequest) -> Form { + fn form(req: &HttpRequest) -> Result, Self::Error> { let file_count = req.app_data::>().expect("Set config"); let file_count = Arc::clone(file_count); - Form::new() + Ok(Form::new() .field("Hey", Field::text()) .field( "Hi", @@ -85,7 +85,7 @@ impl FormData for UploadedContent { .map_err(Errors::from) } })), - ) + )) } fn extract(value: Value) -> Result diff --git a/src/extractor.rs b/src/extractor.rs index e1ebefe..c467abd 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -9,7 +9,7 @@ pub trait FormData { type Item: 'static; type Error: ResponseError + 'static; - fn form(req: &HttpRequest) -> Form; + fn form(req: &HttpRequest) -> Result, Self::Error>; fn extract(value: Value) -> Result where @@ -27,9 +27,11 @@ where fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future { let multipart = actix_multipart::Multipart::new(req.headers(), payload.take()); - let form = Rc::new(T::form(req)); + let res = T::form(req); Box::pin(async move { + let form = Rc::new(res?); + let uploaded = match handle_multipart(multipart, Rc::clone(&form)).await { Ok(Ok(uploaded)) => uploaded, Ok(Err(e)) => return Err(e.into()), diff --git a/src/lib.rs b/src/lib.rs index 3074214..2f4e7f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,8 +38,8 @@ //! type Item = (); //! type Error = Error; //! -//! fn form(_: &HttpRequest) -> Form { -//! Form::new() +//! fn form(_: &HttpRequest) -> Result, Self::Error> { +//! Ok(Form::new() //! .field("Hey", Field::text()) //! .field( //! "Hi", @@ -56,7 +56,7 @@ //! } //! Ok(()) as Result<(), Error> //! })), -//! ) +//! )) //! } //! //! fn extract(value: Value) -> Result diff --git a/src/upload.rs b/src/upload.rs index 41b882d..70b267a 100644 --- a/src/upload.rs +++ b/src/upload.rs @@ -281,6 +281,8 @@ where if !stream_error { while let Some(res) = m.next().await { + tracing::trace!("draining multipart field"); + if let Ok(field) = res { let mut stream = field.into_streamer(); while stream.next().await.is_some() {