pub struct Multipart { /* private fields */ }Available on crate features
server and multipart only.Expand description
Extract a type from multipart/form-data HTTP requests.
Multipart can be passed as an argument to a handler, which can be used to extract each
multipart/form-data field by calling Multipart::next_field.
Notice
Extracting multipart/form-data data will consume the body, hence Multipart must be the
last argument from the handler.
§Example
use http::StatusCode;
use volo_http::{
response::Response,
server::utils::multipart::{Multipart, MultipartRejectionError},
};
async fn upload(mut multipart: Multipart) -> Result<StatusCode, MultipartRejectionError> {
while let Some(field) = multipart.next_field().await? {
todo!()
}
Ok(StatusCode::OK)
}§Body Limitation
Since the body is unlimited, so it is recommended to use
BodyLimitLayer to limit the size of the body.
use http::StatusCode;
use volo_http::{
Router,
server::{
layer::BodyLimitLayer,
route::post,
utils::multipart::{Multipart, MultipartRejectionError},
},
};
async fn upload_handler(
mut multipart: Multipart,
) -> Result<StatusCode, MultipartRejectionError> {
Ok(StatusCode::OK)
}
let app: Router<_> = Router::new()
.route("/", post(upload_handler))
.layer(BodyLimitLayer::new(1024));Implementations§
Source§impl Multipart
impl Multipart
Sourcepub async fn next_field(
&mut self,
) -> Result<Option<Field<'static>>, MultipartRejectionError>
pub async fn next_field( &mut self, ) -> Result<Option<Field<'static>>, MultipartRejectionError>
Trait Implementations§
Source§impl FromRequest for Multipart
impl FromRequest for Multipart
Source§type Rejection = MultipartRejectionError
type Rejection = MultipartRejectionError
If the extractor fails, it will return this
Rejection type. Read moreSource§async fn from_request(
_: &mut ServerContext,
parts: Parts,
body: Body,
) -> Result<Self, Self::Rejection>
async fn from_request( _: &mut ServerContext, parts: Parts, body: Body, ) -> Result<Self, Self::Rejection>
Extract the type from request.
Auto Trait Implementations§
impl Freeze for Multipart
impl !RefUnwindSafe for Multipart
impl Send for Multipart
impl Sync for Multipart
impl Unpin for Multipart
impl !UnwindSafe for Multipart
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more