LaraBABA's avatar

Error with image validation laravel 5.5

Hello,

Could someone please tell me why my validation does not work? I am receiving the image in base64, I tried to decoded it and repass it through the validator by remerging the image in the request.

   public function store(Request $request)
    {
        $encodedImage = $request->get('siteimage');
        $decodedImage = base64_decode($encodedImage);
        $request->merge(['siteimage' => $decodedImage]);

        $validator = Validator::make($request->all(), [
            'description' => 'required|string|min:2|max:750',
            'latitude' => 'required|string|min:2|max:64',
            'longitude' => 'required|string|min:2|max:64',
            'siteimage' => 'required|image|mimes:jpeg,png,jpg|max:20480'
        ],
            $messages = [
                'siteimage.required' => 'You must upload an image!',
                'siteimage.max' => 'Sorry but we do not allow images bigger than 20MB!',
            ]);



        if ($validator->fails()) {
            return response()->json($validator->messages(), 400);

Thanks in advance.

0 likes
2 replies
Nikolaj's avatar

Hi, what kind of response are you getting?

LaraBABA's avatar

Hi, I get the error: siteimage must be an image, the siteimage must be .jpeg.png or jpg

I am wondering if it is right to decode and validate right away. Should the image not be on the disk and then get validated?

Please or to participate in this conversation.