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
impl MultipartStream
Sourcepub fn new(
body: StreamingBody,
content_type: &str,
) -> Result<Self, MultipartError>
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.
Sourcepub const fn bytes_read(&self) -> u64
pub const fn bytes_read(&self) -> u64
Bytes pulled from the transport so far, framing included.
Sourcepub async fn next_field(
&mut self,
) -> Result<Option<MultipartField<'_>>, MultipartError>
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.