How to Send Image or Files in Postman API in 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 .
Now provide your keyname and select type as File as shown below .
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 .
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 :
Thank you for reading this article 😊
For any query do not hesitate to comment 💬