kekekiw123's avatar

Upload images over laravel API

I just finished Jeff's tutorial on "Image manipulation" and it all worked fine.

But now I tried to implement the same code into a restful controller and it wont work. My path gets created but no images gets uploaded, and I dont get any errors.

code:

$input = Input::all();

    $path = public_path() .'/images/123/';


    $x = 1;
    File::exists($path) or File::makeDirectory($path);

    foreach($input['images'] as $file) {


        $thumb = Image::make($file->getRealPath());


        $thumb->fit(130, 107)->save($path . 'thumb_' . $thumbImageName, 100);
        $thumb->destroy(); // destroy thumbnail instance
        $x++; //increment value to only allow one thumbnail

    }

So this wont fire "$thumb = Image::make($file->getRealPath());"

I am using postman in chrome to try this if that matters.

Thanks in advance!

0 likes
5 replies
MladenJanjetovic's avatar

Did you check the raw input, is that file input even there? Is form sending it in the first place?

AddWebContribution's avatar

Postman basically sets a header Content-Type: application/x-www-form-urlencoded by default and this is the cause. So remove that header and check. It should work for you.

Please or to participate in this conversation.