【发布时间】:2018-01-10 00:43:31
【问题描述】:
通过ajax调用在lumen API中上传图片文件,没有拿到lumen中的图片进行处理,Request对象为空。
Ajax 调用
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);
});
路线
$api->post('/image', 'ImagesController@addImage');
控制器
public function addImage(Request $request) {
return $request; // returns empty object
}
【问题讨论】:
-
你解决了这个问题吗?
标签: php ajax laravel api lumen