Share Images the Easy Way: Postman and Laravel

 How to Send Image or Files in Postman API in Laravel

Send Image File using Postman - Laravel

In this article we will see how can you  send your files along with your json data in Postman using Laravel . Let's dive in and see how to send files in Postman .

Step 1 - Postman Setup :

Make your method to POST and goto Body tab and select Form-data as shown below .

Send Image File using Postman - Laravel

Now provide your keyname and select type as File as shown below .

Send Image File using Postman - Laravel

Now simply select your file that you want to store in the database . For example i am selecting an image for uploading as shown below .

Send Image File using Postman - Laravel

That's it your postman is ready to send image or other type of files , you can also send other json data along with your file .

Step 2 - Controller Code :

CheckController.php :

    public function sendImage(Request $request)
    {
        $image=new ImgUpload;  
        if($request->hasfile('image'))  
        {  
            $file=$request->file('image');  
            $extension=$file->getClientOriginalExtension();  
            $filename=time().'.'.$extension;  
            $file->move('public/upload/userimg/',$filename);  
            $image->image=$filename;  
        }  
        else  
        {  
            return $request;  
            $image->image='';  
        }  
        $image->save();
        return response()->json(['response'=>['code'=>'200','message'=>'image uploaded successfull']]);
    }

Now just hit send in postman and you will see it will be uploaded .

Response :

Send Image File using Postman - Laravel



Previous Post Next Post

Contact Form