pub struct MultipartFile<M> {
pub filename: Option<String>,
pub content_type: Mime,
/* private fields */
}Expand description
A representation of a file in HTTP multipart/form-data.
Note that the file is not yet saved to the local filesystem;
instead, this struct exposes Read and BufRead impls which point
to the beginning of the file’s contents in the HTTP stream.
You can read it to EOF, or use one of the save() method
to save it to disk.
Fields§
§filename: Option<String>The filename of this entry, if supplied.
§Warning: Client Provided / Untrustworthy
You should treat this value as untrustworthy because it is an arbitrary string provided by the client.
It is a serious security risk to create files or directories with paths based on user input. A malicious user could craft a path which can be used to overwrite important files, such as web templates, static assets, Javascript files, database files, configuration files, etc., if they are writable by the server process.
This can be mitigated somewhat by setting filesystem permissions as conservatively as possible and running the server under its own user with restricted permissions, but you should still not use user input directly as filesystem paths. If it is truly necessary, you should sanitize filenames such that they cannot be misinterpreted by the OS. Such functionality is outside the scope of this crate.
content_type: MimeThe MIME type (Content-Type value) of this file, if supplied by the client,
or "applicaton/octet-stream" otherwise.
§Note: Client Provided
Consider this value to be potentially untrustworthy, as it is provided by the client. It may be inaccurate or entirely wrong, depending on how the client determined it.
Some variants wrap arbitrary strings which could be abused by a malicious user if your application performs any non-idempotent operations based on their value, such as starting another program or querying/updating a database (web-search “SQL injection”).
Implementations§
Source§impl<M> MultipartFile<M>
impl<M> MultipartFile<M>
Sourcepub fn filename(&self) -> Option<&str>
👎Deprecated since 0.10.0: filename field is now public
pub fn filename(&self) -> Option<&str>
filename field is now publicGet the filename of this entry, if supplied.
§Warning: Client Provided / Untrustworthy
You should treat this value as untrustworthy because it is an arbitrary string provided by the client.
It is a serious security risk to create files or directories with paths based on user input. A malicious user could craft a path which can be used to overwrite important files, such as web templates, static assets, Javascript files, database files, configuration files, etc., if they are writable by the server process.
This can be mitigated somewhat by setting filesystem permissions as conservatively as possible and running the server under its own user with restricted permissions, but you should still not use user input directly as filesystem paths. If it is truly necessary, you should sanitize filenames such that they cannot be misinterpreted by the OS. Such functionality is outside the scope of this crate.
Sourcepub fn content_type(&self) -> &Mime
👎Deprecated since 0.10.0: content_type field is now public
pub fn content_type(&self) -> &Mime
content_type field is now publicGet the MIME type (Content-Type value) of this file, if supplied by the client,
or "applicaton/octet-stream" otherwise.
§Note: Client Provided
Consider this value to be potentially untrustworthy, as it is provided by the client. It may be inaccurate or entirely wrong, depending on how the client determined it.
Some variants wrap arbitrary strings which could be abused by a malicious user if your application performs any non-idempotent operations based on their value, such as starting another program or querying/updating a database (web-search “SQL injection”).
Source§impl<M> MultipartFile<M>where
M: ReadEntry,
impl<M> MultipartFile<M>where
M: ReadEntry,
Sourcepub fn save(&mut self) -> SaveBuilder<&mut MultipartFile<M>>
pub fn save(&mut self) -> SaveBuilder<&mut MultipartFile<M>>
Get a builder type which can save the file with or without a size limit.
Sourcepub fn save_to<W>(&mut self, out: W) -> Result<u64, Error>where
W: Write,
👎Deprecated since 0.10.0: use .save().write_to() instead
pub fn save_to<W>(&mut self, out: W) -> Result<u64, Error>where
W: Write,
.save().write_to() insteadSave this file to the given output stream.
If successful, returns the number of bytes written.
Retries when io::Error::kind() == io::ErrorKind::Interrupted.
Sourcepub fn save_to_limited<W>(&mut self, out: W, limit: u64) -> Result<u64, Error>where
W: Write,
👎Deprecated since 0.10.0: use .save().size_limit(limit).write_to(out) instead
pub fn save_to_limited<W>(&mut self, out: W, limit: u64) -> Result<u64, Error>where
W: Write,
.save().size_limit(limit).write_to(out) insteadSave this file to the given output stream, truncated to limit
(no more than limit bytes will be written out).
If successful, returns the number of bytes written.
Retries when io::Error::kind() == io::ErrorKind::Interrupted.
Sourcepub fn save_as<P>(&mut self, path: P) -> Result<SavedFile, Error>
👎Deprecated since 0.10.0: use .save().with_path(path) instead
pub fn save_as<P>(&mut self, path: P) -> Result<SavedFile, Error>
.save().with_path(path) insteadSave this file to path.
Returns the saved file info on success, or any errors otherwise.
Retries when io::Error::kind() == io::ErrorKind::Interrupted.
Sourcepub fn save_in<P>(&mut self, dir: P) -> Result<SavedFile, Error>
👎Deprecated since 0.10.0: use .save().with_dir(dir) instead
pub fn save_in<P>(&mut self, dir: P) -> Result<SavedFile, Error>
.save().with_dir(dir) insteadSave this file in the directory pointed at by dir,
using a random alphanumeric string as the filename.
Any missing directories in the dir path will be created.
Returns the saved file’s info on success, or any errors otherwise.
Retries when io::Error::kind() == io::ErrorKind::Interrupted.
Sourcepub fn save_as_limited<P>(
&mut self,
path: P,
limit: u64,
) -> Result<SavedFile, Error>
👎Deprecated since 0.10.0: use .save().size_limit(limit).with_path(path) instead
pub fn save_as_limited<P>( &mut self, path: P, limit: u64, ) -> Result<SavedFile, Error>
.save().size_limit(limit).with_path(path) insteadSave this file to path, truncated to limit (no more than limit bytes will be written out).
Any missing directories in the dir path will be created.
Returns the saved file’s info on success, or any errors otherwise.
Retries when io::Error::kind() == io::ErrorKind::Interrupted.
Sourcepub fn save_in_limited<P>(
&mut self,
dir: P,
limit: u64,
) -> Result<SavedFile, Error>
👎Deprecated since 0.10.0: use .save().size_limit(limit).with_dir(dir) instead
pub fn save_in_limited<P>( &mut self, dir: P, limit: u64, ) -> Result<SavedFile, Error>
.save().size_limit(limit).with_dir(dir) insteadSave this file in the directory pointed at by dir,
using a random alphanumeric string as the filename.
Truncates file to limit (no more than limit bytes will be written out).
Any missing directories in the dir path will be created.
Returns the saved file’s info on success, or any errors otherwise.
Retries when io::Error::kind() == io::ErrorKind::Interrupted.
Trait Implementations§
Source§impl<M> BufRead for MultipartFile<M>where
M: ReadEntry,
impl<M> BufRead for MultipartFile<M>where
M: ReadEntry,
Source§fn fill_buf(&mut self) -> Result<&[u8], Error>
fn fill_buf(&mut self) -> Result<&[u8], Error>
Read methods, if empty. Read moreSource§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amount of additional bytes from the internal buffer as having been read.
Subsequent calls to read only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA byte) is reached, and append
them to the provided String buffer. Read moreSource§impl<M> Debug for MultipartFile<M>where
M: Debug,
impl<M> Debug for MultipartFile<M>where
M: Debug,
Source§impl<M> Read for MultipartFile<M>where
M: ReadEntry,
impl<M> Read for MultipartFile<M>where
M: ReadEntry,
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Auto Trait Implementations§
impl<M> Freeze for MultipartFile<M>where
M: Freeze,
impl<M> RefUnwindSafe for MultipartFile<M>where
M: RefUnwindSafe,
impl<M> Send for MultipartFile<M>where
M: Send,
impl<M> Sync for MultipartFile<M>where
M: Sync,
impl<M> Unpin for MultipartFile<M>where
M: Unpin,
impl<M> UnwindSafe for MultipartFile<M>where
M: UnwindSafe,
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
Source§impl<R> ReadBytesExt for R
impl<R> ReadBytesExt for R
Source§fn read_u8(&mut self) -> Result<u8, Error>
fn read_u8(&mut self) -> Result<u8, Error>
Source§fn read_i8(&mut self) -> Result<i8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
Source§fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
Source§fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
Source§fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
Source§fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
Source§fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
Source§fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
Source§fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
Source§fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
Source§fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
Source§fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
Source§fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
Source§fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
Source§fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
Source§fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
Source§fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
Source§fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
Source§fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
read_f32_into insteadSource§impl<R> TrustRead for Rwhere
R: Read,
impl<R> TrustRead for Rwhere
R: Read,
Source§fn is_trusted(&self) -> bool
fn is_trusted(&self) -> bool
Default impl which always returns false.
Enable the nightly feature to specialize this impl for various types.