Uploading the image file in lumen API using ajax call, it not getting the image in the lumen for processing, the Request object is empty.
Ajax call
var file = $('#img')[0].files[0];
var form_data = new FormData(document.getElementById("myform"));
form_data.append("img", file);
$.ajax({
url: "http://localhost:8000/api/image",
type: "POST",
data: form_data,
enctype: 'multipart/form-data',
processData: false, // tell jQuery not to process the data
contentType: false // tell jQuery not to set contentType
})
.done(function (data) {
console.log(data);
});
Route
$api->post('/image', 'ImagesController@addImage');
Controller
public function addImage(Request $request) {
return $request; // returns empty object
}