pub struct FileUploadParser {
pub max_file_size: Option<usize>,
pub field_name: String,
}Expand description
Raw file upload parser
Fields§
§max_file_size: Option<usize>Maximum file size in bytes (None = unlimited)
field_name: StringField name for the file
Implementations§
Source§impl FileUploadParser
impl FileUploadParser
Sourcepub fn get_filename(
&self,
content_disposition: Option<&str>,
) -> Result<String, Error>
pub fn get_filename( &self, content_disposition: Option<&str>, ) -> Result<String, Error>
Parse filename from Content-Disposition header. Supports both standard filename and RFC2231 encoded filename* parameters.
§Examples
use reinhardt_core::parsers::file::FileUploadParser;
let parser = FileUploadParser::new("file");
let disposition = "inline; filename=document.txt";
let filename = parser.get_filename(Some(disposition)).unwrap();
assert_eq!(filename, "document.txt");
let disposition_encoded = "inline; filename*=utf-8''%C3%A0.txt";
let filename_encoded = parser.get_filename(Some(disposition_encoded)).unwrap();
assert_eq!(filename_encoded, "à.txt");Source§impl FileUploadParser
impl FileUploadParser
Sourcepub fn new(field_name: impl Into<String>) -> FileUploadParser
pub fn new(field_name: impl Into<String>) -> FileUploadParser
Create a new FileUploadParser with the specified field name.
§Examples
use reinhardt_core::parsers::file::FileUploadParser;
let parser = FileUploadParser::new("document");
assert_eq!(parser.field_name, "document");
assert!(parser.max_file_size.is_none());Sourcepub fn max_file_size(self, size: usize) -> FileUploadParser
pub fn max_file_size(self, size: usize) -> FileUploadParser
Set the maximum file size in bytes.
§Examples
use reinhardt_core::parsers::file::FileUploadParser;
let parser = FileUploadParser::new("file").max_file_size(5 * 1024 * 1024); // 5MB
assert_eq!(parser.max_file_size, Some(5 * 1024 * 1024));Trait Implementations§
Source§impl Clone for FileUploadParser
impl Clone for FileUploadParser
Source§fn clone(&self) -> FileUploadParser
fn clone(&self) -> FileUploadParser
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FileUploadParser
impl Debug for FileUploadParser
Source§impl Default for FileUploadParser
impl Default for FileUploadParser
Source§fn default() -> FileUploadParser
fn default() -> FileUploadParser
Returns the “default value” for a type. Read more
Source§impl Parser for FileUploadParser
impl Parser for FileUploadParser
Source§fn media_types(&self) -> Vec<String>
fn media_types(&self) -> Vec<String>
Get the media types this parser can handle
Source§fn parse<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
content_type: Option<&'life1 str>,
body: Bytes,
_headers: &'life2 HeaderMap,
) -> Pin<Box<dyn Future<Output = Result<ParsedData, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
FileUploadParser: 'async_trait,
fn parse<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
content_type: Option<&'life1 str>,
body: Bytes,
_headers: &'life2 HeaderMap,
) -> Pin<Box<dyn Future<Output = Result<ParsedData, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
FileUploadParser: 'async_trait,
Parse the request body
Auto Trait Implementations§
impl Freeze for FileUploadParser
impl RefUnwindSafe for FileUploadParser
impl Send for FileUploadParser
impl Sync for FileUploadParser
impl Unpin for FileUploadParser
impl UnsafeUnpin for FileUploadParser
impl UnwindSafe for FileUploadParser
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
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>
Converts
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>
Converts
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<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().