pub struct Upload { /* private fields */ }Available on crate feature
fs only.Expand description
The result of a completed multipart parse with storage: text fields, owned and wiped on drop, and files.
§Examples
let body = b"--X\r\nContent-Disposition: form-data; name=title\r\n\r\nHoliday\r\n--X\r\nContent-Disposition: form-data; name=photo; filename=a.jpg\r\n\r\nJPEG\r\n--X--";
let mut upload = form_net::read_multipart(b"multipart/form-data; boundary=X", &body[..])?;
assert_eq!(upload.field("title"), Some("Holiday"));
let photo = upload.take_file("photo").unwrap();
assert_eq!(photo.bytes(), Some(&b"JPEG"[..]));
assert_eq!(upload.file_count(), 0);Implementations§
Source§impl Upload
impl Upload
Sourcepub fn fields<'u>(&'u self, name: &'u str) -> impl Iterator<Item = &'u str> + 'u
pub fn fields<'u>(&'u self, name: &'u str) -> impl Iterator<Item = &'u str> + 'u
Every text field named name, in body order.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Every text field (name, value), in body order.
Sourcepub fn file(&self, name: &str) -> Option<&StoredFile>
pub fn file(&self, name: &str) -> Option<&StoredFile>
The first file named name.
Sourcepub fn files<'u>(
&'u self,
name: &'u str,
) -> impl Iterator<Item = &'u StoredFile> + 'u
pub fn files<'u>( &'u self, name: &'u str, ) -> impl Iterator<Item = &'u StoredFile> + 'u
Every file named name, in body order.
Sourcepub fn take_file(&mut self, name: &str) -> Option<StoredFile>
pub fn take_file(&mut self, name: &str) -> Option<StoredFile>
Removes and returns the first file named name.
Sourcepub fn into_files(self) -> Vec<StoredFile>
pub fn into_files(self) -> Vec<StoredFile>
Every file, in body order.
Sourcepub fn captured_token(&self) -> Option<&str>
pub fn captured_token(&self) -> Option<&str>
The anti-forgery token field’s value, when a token field was set.
Sourcepub fn file_count(&self) -> usize
pub fn file_count(&self) -> usize
The number of files.
Sourcepub fn parse_with<R: Read, I: Inspector>(
content_type: &[u8],
reader: R,
limits: &Limits,
policy: &Policy,
store: &Store,
inspector: &mut I,
) -> Result<Upload, FormError>
pub fn parse_with<R: Read, I: Inspector>( content_type: &[u8], reader: R, limits: &Limits, policy: &Policy, store: &Store, inspector: &mut I, ) -> Result<Upload, FormError>
Reads a whole multipart body from reader in 64 KiB chunks, with
explicit limits, policy, store, and inspector.
§Errors
Every multipart error; Refused; Io { kind }; Store { .. };
Limit { Disk }.
§Examples
use form_net::{Limits, NoInspector, Policy, Store, TokenField, Upload};
let store = Store::temp()?;
let policy = Policy::DEFAULT.with_token_field(TokenField::new("csrf_token"));
let body = b"--X\r\nContent-Disposition: form-data; name=csrf_token\r\n\r\ntok\r\n--X--";
let upload = Upload::parse_with(b"multipart/form-data; boundary=X", &body[..], &Limits::DEFAULT, &policy, &store, &mut NoInspector)?;
assert_eq!(upload.captured_token(), Some("tok"));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Upload
impl RefUnwindSafe for Upload
impl Send for Upload
impl Sync for Upload
impl Unpin for Upload
impl UnsafeUnpin for Upload
impl UnwindSafe for Upload
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more