0

I have some struggles with image validation with Laravel.

I'm sending data from vue.js, and json looks like:

images: [
   "data:image/png;base64, codehere",
    "data:image/png;base64, codehere",
]

And my validator looks like:

'images.*' => 'file|image|mimes:jpg,png,jpeg,gif,svg',

and every time when I try to validate images, i have error like

The images.0 must be an image.

What am I doing wrong here?

Ram Chander
  • 1,088
  • 2
  • 18
  • 36
  • 1
    Does this answer your question? [Validate a base64 decoded image in laravel](https://stackoverflow.com/questions/39042731/validate-a-base64-decoded-image-in-laravel) – jrcamatog Apr 01 '21 at 12:39

2 Answers2

1

I faced with this issue when I upgraded laravel framework from 5.5 to 5.6. jpeg and jpg files had this issue in image validation. my validation was like this :

'img' => 'image|mimes:jpeg,png,jpg,gif,svg|max:5000

I removed the image and just left the mime part and it worked! like this:

'img' => 'mimes:jpeg,png,jpg,gif,svg|max:5000
Dharman
  • 30,962
  • 25
  • 85
  • 135
blank94
  • 374
  • 3
  • 20
0

You can use it two different methods.

We can use the first option:

$validate = $this->validate($request, [
    'description' => 'required',
    'image_path' => 'mimes:jpeg,png,jpg,gif,svg|required|max:20000'
]);

Or this second option :

$validate = $this->validate($request, [
    'description' => 'required',
    'image_path' => 'required|image'
]);  

List of mines type - images

Jatniel
  • 1,967
  • 2
  • 19
  • 27