pub struct Upload { /* private fields */ }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 from_form(form: Form, policy: &Policy) -> Result<Upload, FormError>
pub fn from_form(form: Form, policy: &Policy) -> Result<Upload, FormError>
One owned type for both encodings (D-090, D-098): the fields of a
urlencoded form as an upload with no files, so a server keeps one
Upload per request whatever the Content-Type. The policy’s token
field is captured as a multipart parse would capture it, so
captured_token means the same for both.
The form is wiped as it drops.
§Errors
Policy { DuplicateToken } when the token field appears twice.
§Examples
use form_net::{Policy, TokenField, Upload};
let policy = Policy::DEFAULT.with_token_field(TokenField::new("csrf"));
let form = form_net::parse_urlencoded(b"email=a%40b.example&csrf=t0k&tag=x&tag=y")?;
let upload = Upload::from_form(form, &policy)?;
assert_eq!(upload.field("email"), Some("a@b.example"));
assert_eq!(upload.captured_token(), Some("t0k"));
assert_eq!((upload.fields("tag").count(), upload.file_count()), (2, 0));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.