pub struct Part { /* private fields */ }
Available on crate feature
multipart
only.Expand description
A single part of a multipart form as defined by https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4 and RFC5758.
Implementations§
Source§impl Part
impl Part
Sourcepub fn text(name: String, contents: &str) -> Self
pub fn text(name: String, contents: &str) -> Self
Create a new part with Content-Type
of text/plain
with the supplied name and contents.
This form will not have a defined file name.
§Examples
use axum_extra::response::multiple::{MultipartForm, Part};
// create a form with a single part that has a field with a name of "foo",
// and a value of "abc"
let parts: Vec<Part> = vec![Part::text("foo".to_string(), "abc")];
let form = MultipartForm::from_iter(parts);
Sourcepub fn file(field_name: &str, file_name: &str, contents: Vec<u8>) -> Self
pub fn file(field_name: &str, file_name: &str, contents: Vec<u8>) -> Self
Create a new part containing a generic file, with a Content-Type
of application/octet-stream
using the provided file name, field name, and contents.
If the MIME type of the file is known, consider using Part::raw_part
.
§Examples
use axum_extra::response::multiple::{MultipartForm, Part};
// create a form with a single part that has a field with a name of "foo",
// with a file name of "foo.txt", and with the specified contents
let parts: Vec<Part> = vec![Part::file("foo", "foo.txt", vec![0x68, 0x68, 0x20, 0x6d, 0x6f, 0x6d])];
let form = MultipartForm::from_iter(parts);
Sourcepub fn raw_part(
name: &str,
mime_type: &str,
contents: Vec<u8>,
filename: Option<&str>,
) -> Result<Self, &'static str>
pub fn raw_part( name: &str, mime_type: &str, contents: Vec<u8>, filename: Option<&str>, ) -> Result<Self, &'static str>
Create a new part with more fine-grained control over the semantics of that part.
The caller is assumed to have set a valid MIME type.
This function will return an error if the provided MIME type is not valid.
§Examples
use axum_extra::response::multiple::{MultipartForm, Part};
// create a form with a single part that has a field with a name of "part_name",
// with a MIME type of "application/json", and the supplied contents.
let parts: Vec<Part> = vec![Part::raw_part("part_name", "application/json", vec![0x68, 0x68, 0x20, 0x6d, 0x6f, 0x6d], None).expect("MIME type must be valid")];
let form = MultipartForm::from_iter(parts);
Trait Implementations§
Source§impl FromIterator<Part> for MultipartForm
impl FromIterator<Part> for MultipartForm
Auto Trait Implementations§
impl Freeze for Part
impl RefUnwindSafe for Part
impl Send for Part
impl Sync for Part
impl Unpin for Part
impl UnwindSafe for Part
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