Skip to main content

Multipart

Struct Multipart 

Source
pub struct Multipart { /* private fields */ }
Expand description

Streaming multipart/form-data extractor. Parts arrive in wire order and must be consumed sequentially; next_part discards any unread remainder of the previous part. Requires content-type: multipart/form-data with a valid boundary — anything else is 415 JC0415.

Single-consumer: the extractor takes ownership of the body, so extracting it twice in one handler is a programming error (500 on stream routes).

Implementations§

Source§

impl Multipart

Source

pub fn from_buffered(content_type: &str, body: impl Into<Bytes>) -> Option<Self>

Build a buffered Multipart from an already-read body and its Content-Type header value, or None if the content type is not multipart/form-data with a valid boundary.

The Multipart extractor (FromRequest) is the normal path and is 415 on a non-multipart request. This constructor exists for handlers that must accept either a multipart upload or some other content type on the same route (e.g. a CSV import endpoint whose generated success probe posts an empty JSON body): take Headers + RawBody, then Multipart::from_buffered when the type matches. The parsing is identical to the extractor’s buffered path.

Source

pub fn set_part_cap(&mut self, bytes: usize)

Per-part byte cap enforced by Part::bytes/Part::text (default 8 MiB).

Source

pub async fn next_part(&mut self) -> Result<Option<Part<'_>>>

The next part, or None after the closing boundary. Any unread data of the current part is discarded first.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.