pub struct MultipartField<'stream> { /* private fields */ }Expand description
One part of a streamed multipart/form-data body.
Dropping a field without reading it to the end is allowed; the next
MultipartStream::next_field call skips whatever is left.
Implementations§
Source§impl MultipartField<'_>
impl MultipartField<'_>
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
The part’s declared media type, when it has one.
Sourcepub async fn next_chunk(&mut self) -> Result<Option<&[u8]>, MultipartError>
pub async fn next_chunk(&mut self) -> Result<Option<&[u8]>, MultipartError>
Pulls the next run of this part’s data.
The slice borrows the reader’s buffer and is valid until the next call,
so nothing is copied on the way to the handler. Returns None once the
part’s closing delimiter has been reached.
§Errors
Returns MultipartError when the document ends before its closing
delimiter or when the transport fails.
Sourcepub async fn collect(self, limit: usize) -> Result<Vec<u8>, MultipartError>
pub async fn collect(self, limit: usize) -> Result<Vec<u8>, MultipartError>
Deliberately buffers the rest of this part, with an explicit limit.
§Errors
Returns MultipartError::TooLarge when the part is longer than
limit, or the reader failure that stopped it.
Sourcepub async fn text(self, limit: usize) -> Result<String, MultipartError>
pub async fn text(self, limit: usize) -> Result<String, MultipartError>
Deliberately buffers the rest of this part as text.
§Errors
Returns MultipartError::TooLarge when the part is longer than
limit, MultipartError::Malformed when it is not UTF-8, or the
reader failure that stopped it.
Sourcepub async fn into_upload(
self,
limit: usize,
) -> Result<UploadFile, MultipartError>
pub async fn into_upload( self, limit: usize, ) -> Result<UploadFile, MultipartError>
Deliberately buffers the rest of this part as an UploadFile.
This is the bridge to the buffered API: an operation that wants the
bytes after all gets the same value the File<UploadFile> extractor
would have produced, having chosen the limit itself.
§Errors
Returns MultipartError::TooLarge when the part is longer than
limit, or the reader failure that stopped it.