pub struct NamedFile { /* private fields */ }
Expand description
A file with an associated name.
Implementations§
Source§impl NamedFile
impl NamedFile
Sourcepub fn new(file_name: impl Into<String>) -> Self
pub fn new(file_name: impl Into<String>) -> Self
Creates a new instance with the specific file name.
Sourcepub fn set_field_name(&mut self, field_name: impl Into<String>)
pub fn set_field_name(&mut self, field_name: impl Into<String>)
Sets the field name.
Sourcepub fn set_file_name(&mut self, file_name: impl Into<String>)
pub fn set_file_name(&mut self, file_name: impl Into<String>)
Sets the file name.
Sourcepub fn set_content_type(&mut self, content_type: Mime)
pub fn set_content_type(&mut self, content_type: Mime)
Sets the content type.
Sourcepub fn set_extra_attribute(&mut self, key: &str, value: impl Into<JsonValue>)
pub fn set_extra_attribute(&mut self, key: &str, value: impl Into<JsonValue>)
Sets the extra attribute.
§Note
Currently, we support the following built-in attributes:
checksum
| chunk_number
| chunk_size
| total_chunks
.
Sourcepub fn append_extra_attributes(&mut self, attrs: &mut Map)
pub fn append_extra_attributes(&mut self, attrs: &mut Map)
Appends the extra attributes.
Sourcepub fn field_name(&self) -> Option<&str>
pub fn field_name(&self) -> Option<&str>
Returns the field name corresponding to the file.
Sourcepub fn content_type(&self) -> Option<&Mime>
pub fn content_type(&self) -> Option<&Mime>
Returns the content type.
Sourcepub fn chunk_number(&self) -> Option<usize>
pub fn chunk_number(&self) -> Option<usize>
Returns the chunk number for the file.
Sourcepub fn chunk_size(&self) -> Option<usize>
pub fn chunk_size(&self) -> Option<usize>
Returns the chunk size for the file.
Sourcepub fn total_chunks(&self) -> Option<usize>
pub fn total_chunks(&self) -> Option<usize>
Returns the total number of file chunks.
Sourcepub fn checksum(&self) -> Bytes
pub fn checksum(&self) -> Bytes
Returns the checksum for the file.
§Note
If you would like to obtain a hex-formated string,
you can use the LowerHex
or UpperHex
implementations for Bytes
.
Sourcepub fn content_md5(&self) -> String
pub fn content_md5(&self) -> String
Returns the content MD5.
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Returns the hex representation of the file bytes.
Sourcepub fn to_base64_string(&self) -> String
pub fn to_base64_string(&self) -> String
Returns the base64 representation of the file bytes.
Sourcepub fn read_string(&mut self, data: String) -> Result<(), Error>
pub fn read_string(&mut self, data: String) -> Result<(), Error>
Reads the string and sets the bytes.
Sourcepub fn read_hex_string(&mut self, data: &str) -> Result<(), Error>
pub fn read_hex_string(&mut self, data: &str) -> Result<(), Error>
Reads the hex string and sets the bytes.
Sourcepub fn read_base64_string(&mut self, data: &str) -> Result<(), Error>
pub fn read_base64_string(&mut self, data: &str) -> Result<(), Error>
Reads the base64 string and sets the bytes.
Sourcepub fn read_from_local(&mut self, path: impl AsRef<Path>) -> Result<(), Error>
pub fn read_from_local(&mut self, path: impl AsRef<Path>) -> Result<(), Error>
Reads the entire contents of a local file and sets the bytes.
Sourcepub fn write(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub fn write(&self, path: impl AsRef<Path>) -> Result<(), Error>
Writes the bytes into a file at the path.
If the extra attributes contain a chunk_number
value,
a .{chunk_number}.part
suffix will be adjoined to the path.
Sourcepub fn append(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub fn append(&self, path: impl AsRef<Path>) -> Result<(), Error>
Appends the bytes into a file at the path.
Sourcepub fn encrypt_with(&mut self, key: impl AsRef<[u8]>) -> Result<(), Error>
pub fn encrypt_with(&mut self, key: impl AsRef<[u8]>) -> Result<(), Error>
Encrypts the file with a key.
Sourcepub fn decrypt_with(&mut self, key: impl AsRef<[u8]>) -> Result<(), Error>
pub fn decrypt_with(&mut self, key: impl AsRef<[u8]>) -> Result<(), Error>
Decrypts the file with a key.
Sourcepub fn rename_file_stem(&mut self, file_stem: &str) -> Result<(), Error>
pub fn rename_file_stem(&mut self, file_stem: &str) -> Result<(), Error>
Renames the stem portion of the file name.
Sourcepub fn split_chunks(&self, chunk_size: usize) -> Vec<Self>
pub fn split_chunks(&self, chunk_size: usize) -> Vec<Self>
Splits the file into chunks with the chunk_size
.
The file name of chunks will end with .{chunk_number}.part
and the extra attributes will contain the chunk_number
and total_chunks
.
Sourcepub fn try_concat_chunks(
path: impl AsRef<Path>,
total_chunks: usize,
) -> Result<Self, Error>
pub fn try_concat_chunks( path: impl AsRef<Path>, total_chunks: usize, ) -> Result<Self, Error>
Attempts to concat the file chunks into a whole.
The path should not contain the .{chunk_number}.part
suffix.
Sourcepub fn try_from_local(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn try_from_local(path: impl AsRef<Path>) -> Result<Self, Error>
Attempts to create an instance from reading a local file.
Sourcepub async fn try_from_multipart_field(field: Field<'_>) -> Result<Self, Error>
pub async fn try_from_multipart_field(field: Field<'_>) -> Result<Self, Error>
Attempts to create an instance from a field in a multipart stream.
Sourcepub async fn try_from_multipart(multipart: Multipart<'_>) -> Result<Self, Error>
pub async fn try_from_multipart(multipart: Multipart<'_>) -> Result<Self, Error>
Attempts to create a file in a multipart stream.
If the extra attributes contain a chunk_size
or checksum
value,
the file integrity will be checked.
Sourcepub async fn try_collect_from_multipart(
multipart: Multipart<'_>,
) -> Result<Vec<Self>, Error>
pub async fn try_collect_from_multipart( multipart: Multipart<'_>, ) -> Result<Vec<Self>, Error>
Attempts to create a list of files in a multipart stream.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for NamedFile
impl RefUnwindSafe for NamedFile
impl Send for NamedFile
impl Sync for NamedFile
impl Unpin for NamedFile
impl UnwindSafe for NamedFile
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)