pub fn ext<'v>(file: &TempFile<'_>, type: ContentType) -> Result<'v, ()>
Expand description
File type validator: succeeds when a TempFile
has the Content-Type
content_type
.
On failure, returns a validation error with one of the following messages:
// the file has an incorrect extension
file type was .$file_ext but must be $type
// the file does not have an extension
file type must be $type
Example
use rocket::form::FromForm;
use rocket::data::ToByteUnit;
use rocket::http::ContentType;
use rocket::fs::TempFile;
#[derive(FromForm)]
struct Foo<'r> {
#[field(validate = ext(ContentType::PDF))]
#[field(validate = len(..1.mebibytes()))]
document: TempFile<'r>,
}