0
votes

i'm creating an API in Laravel 5.5 and this API supports receiving some files for profile pictures and such.

I want to limit this through a form request to accept only JPG and PNG images and i'm setting up my Form Request as follows:

    'picture'    => 'nullable|image|mimetypes:image/jpeg,image/png,image/jpg|max:2000' // 2000KB or around 2MB per picture

Then, on my PHPUnit/Codeception tests i'm sending a fake image using Laravel's own fake static method as follows

'picture' => UploadedFile::fake()->image("hello.svg")

If i DD the image file that is being sent when i run the test it correctly lists it's MIMEType as image/svg+xml, however, somehow this passes validation and comes out the other end and that should not be the case as my rule should limit only PNG or JPG files.

Does anyone else have this issue?

2

2 Answers

1
votes

Make sure your form has an attribute enctype="multipart/form-data"

You can read about the enctype attribute here : What does enctype='multipart/form-data' mean?

0
votes

you wrote wrong syntax to validate picture type in picture validation.

you need just to create picture validation like this :

'picture' => 'nullable|image|mimes:jpeg,png|max:2000'