I've been trying to write an api to upload image to server ,but all in vain. I'm using the laravel framework .And tried this example but it is not working.
Also while testing the api from POSTMAN ,I have passed mutlipart/form-data in the Headers.And in the Body tab selected form-data, added key = image, changed it Text to File and added an image.But when I test the api , don't know why but the image request is empty.
Maybe I might be passing something wrong in POSTMAN or there might be something wrong in my code,please do help me.
Here's my api code
public function upload(Request $request){
if ($request->hasFile('image')) {
$image = $request->file('image');
$name = md5(time().uniqid()).".png";
$destinationPath = base_path() . '/public/uploads/images/' . $name;
move_uploaded_file($name, $destinationPath);
return response()->json(['title'=>"image is uploaded"]);
}
}
And my controller code :
Route::post('uploadImage','TestController@upload');
Screenshot of the postman request.Please tell me if I'm passing something wrong in header or body .
Also ,the console shows this error Missing boundary in multipart/form-data POST data in Unknown on line 0