Laravel 5.1 Validation failing on correct mime/extension

laravel validation
laravel validation unique except
image validation laravel
laravel model validation
laravel mimes validation not working
laravel validation rules list
laravel date format validation
laravel custom validation error messages

I use a request class for my validation. I have a request class that has this piece of code in there:

public function rules()
{
    $rules = [
        'attachment'  => 'mimes:png,jpg,gif'
    ];
}

Doing a $request->file('attachment')->getClientMimeType() in my controller returns image/png

Yet whenever I try to send a png file I'm still getting a validation error: "The attachments must be a file of type: png, jpg, gif."

I'm using a rest client called Paw to send the file to the backend via a Multipart form

Am I missing a step?

EDIT: I cannot use image as a validation rule because I eventually want to start accepting pdf/doc and other formats (image fails btw). So far both PDF and doc has also failed validation.


I know this thread is old, but this might help others who may stumbled on the same problem. I am using "attachments[]" as input name by the way. And I got it working using this:

$this->validate(request(), [
        'attachments.*' => 'required|mimes:jpeg,png,pdf'
]);

using the dot(.) asterisk solved my problem.

Laravel 5.1 Validation failing on correct mime/extension, Laravel 5.1 Validation failing on correct mime/extension. Posted 4 years ago by zakiaziz. I use a request class for my validation. I have a  Forum Laravel Laravel 5.1 Validation failing on correct mime/extension. Reply Follow All Threads Laravel 5.1 Validation failing on correct mime/extension


According to W3Schools when you upload a file you must mention multipart/form-data so no characters would be encoded,which probably cause the validation fail.

Validation - Laravel, Master, 7.x, 6.x · 5.8 · 5.7 · 5.6 · 5.5 · 5.4 · 5.3 · 5.2 · 5.1 · 5.0 · 4.2 Using Rule Objects; Using Closures; Using Extensions; Implicit Extensions Again, if the validation fails, the proper response will automatically be generated. Than Less Than Or Equal Max MIME Types MIME Type By File Extension Min Not In Not Regex  'document_file.mimes' => 'Your document is not the correct format.', Any ideas that i am missing or need to check for this. Are the setting I need to add, could it be a server side issue etc. NB: I am using the validation class outside of laravel as well. thanks in advance


I also ran into this problem and nothing worked for me. cause the code works well locally and on my ubuntu server online it fails. What worked for me was to remove the laravel validation and use normal php validation. Sometimes simplicity is just what works.enter image description here

Validation - Lumen, You may also access an array of the failed validation rules, without messages. validation must have a MIME type corresponding to one of the listed extensions. Ok, I’m trying to upload a video, and validate the file type. According to the documentation: mimes:foo,bar,… The file under validation must have a MIME type corresponding to one of the listed extensions. Basic Usage Of MIME Rule ‘photo’ => ‘mimes:jpeg,bmp,png’ I’m uploading a wmv video, and my rules are so:


php - Laravel / Validation does not work with my file input?, Again, if the validation fails, the proper response will automatically be generated. The file under validation must have a MIME type corresponding to one of the  The file under validation must have a MIME type corresponding to one of the listed extensions. Basic Usage Of MIME Rule 'photo' => 'mimes:jpeg,bmp,png' Even though you only need to specify the extensions, this rule actually validates against the MIME type of the file by reading the file's contents and guessing its MIME type.


mimes validator always returning errors even with right mime type., yup, that's not correct. php - File upload form validation is not working in laravel 5.1? and validate it ends in .docx otherwise it will delete the file and throw an error. php - File upload mime-type validation with Laravel 4 - Stack Overflow. Validating .msg file uploads using Laravel's Mime validation Posted 1 year ago by christian_H Hey everyone, I'm trying to add .msg files (Microsoft Outlook's main file type for saving emails) to some existing file upload validation.


request validate laravel 5.1 Code Example, Forum > Laravel 5: mimes validator always returning errors even with right mime type. tbergeron posted 5 years ago. Validation. The file under validation must have a MIME type corresponding to one of the listed extensions. Basic Usage Of MIME Rule 'photo' => 'mimes:jpeg,bmp,png' min:value. The field under validation must have a minimum value. Strings, numerics, and files are evaluated in the same fashion as the size rule. not_in:foo,bar,