pub struct BodyPart { /* private fields */ }Expand description
A single part of a multipart/form-data body.
A part carries the form field name declared by its Content-Disposition
header, the file name of an uploaded file when the part is a file, the
headers that belong to the part alone, and its raw content.
Storage is pub(super) (§17.14): a caller never touches the fields
directly. The public read surface is the try_get_* family below,
which follows the same Option-returning convention as
crate::Request and crate::Response and therefore never fails
loudly on a part that lacks an optional attribute.
Implementations§
Source§impl BodyPart
impl BodyPart
Sourcepub fn try_get_name(&self) -> Option<&String>
pub fn try_get_name(&self) -> Option<&String>
Tries to get the form field name of this part.
§Returns
Option<&BodyPartName>- The declared field name, orNonewhen the part declares none.
Sourcepub fn try_get_file_name(&self) -> Option<&String>
pub fn try_get_file_name(&self) -> Option<&String>
Tries to get the uploaded file name of this part.
§Returns
Option<&BodyPartFileName>- The declared file name, orNonewhen this part is a plain field rather than a file upload.
Sourcepub fn try_get_content_type(&self) -> Option<&String>
pub fn try_get_content_type(&self) -> Option<&String>
Tries to get the media type declared by this part.
§Returns
Option<&BodyPartContentType>- The declared media type, orNonewhen the part declares none.
Sourcepub fn try_get_header<K>(&self, key: K) -> Option<&String>
pub fn try_get_header<K>(&self, key: K) -> Option<&String>
Sourcepub fn try_get_data(&self) -> Option<&[u8]>
pub fn try_get_data(&self) -> Option<&[u8]>
Tries to get this part’s raw content.
§Returns
Option<&[u8]>- The raw bytes, orNonewhen the part is empty.
Sourcepub fn try_get_text(&self) -> Option<String>
pub fn try_get_text(&self) -> Option<String>
Tries to get this part’s raw content as UTF-8 text.
Invalid UTF-8 is replaced rather than rejected, so a binary upload
read as text yields its readable bytes instead of None.
§Returns
Option<BodyFormValue>- The decoded text, orNonewhen the part is empty.