Skip to main content

MultipartStream

Struct MultipartStream 

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

A multipart/form-data request body read part by part, chunk by chunk.

The buffered Multipart<T> extractor materializes every part before the handler starts, which costs resident memory proportional to the requests in flight. This reader instead drives the pull-based request body: it holds one transport chunk plus, at most, a delimiter’s worth of look-ahead, whatever the upload’s size. A handler that counts bytes and drops them holds nothing.

Transport limits are not re-implemented here. The stream this reads from is the adapter’s, so the decoded-size limit, the chunk-count limit, and the body read deadline apply exactly as they do to StreamingBody itself, and they apply while the body is arriving rather than after it has all been accepted.

§Examples

let mut bytes = 0;
while let Some(mut field) = multipart.next_field().await? {
    if field.name() != "file" {
        continue;
    }
    while let Some(chunk) = field.next_chunk().await? {
        bytes += chunk.len();
    }
}

Implementations§

Source§

impl MultipartStream

Source

pub fn new( body: StreamingBody, content_type: &str, ) -> Result<Self, MultipartError>

Reads body as the multipart/form-data document content_type describes.

§Errors

Returns MultipartError::Malformed when content_type is not multipart/form-data with a usable boundary.

Source

pub const fn bytes_read(&self) -> u64

Bytes pulled from the transport so far, framing included.

Source

pub async fn next_field( &mut self, ) -> Result<Option<MultipartField<'_>>, MultipartError>

Advances to the next part, skipping whatever is left of the current one.

Returns None once the closing delimiter has been read.

§Errors

Returns MultipartError when the document is malformed, when it ends before its closing delimiter, or when the transport fails.

Trait Implementations§

Source§

impl Debug for MultipartStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> BackgroundExt for T

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<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> ResponseExt for T

Source§

fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> WithHeaders<Self>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.