[英]Request is empty when POST from Angular with FormData in LUMEN
我正在尝试将文件上传到LUMEN后端。
发送到后端的标头是:
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Authorization: Bearer
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 1034
Content-Type: multipart/form-data
Host: localhost:8000
Origin: http://evil.com/
Pragma: no-cache
Referer: http://localhost:4200/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
有效负载是一个formData,并附加了一个文件:
------WebKitFormBoundaryBh1H2ML8XFieaS2c
Content-Disposition: form-data; name="file[]"; filename="exportSales.csv"
Content-Type: text/csv
------WebKitFormBoundaryBh1H2ML8XFieaS2c--
上传文件的前端方法是:
store(file): Observable<{}> {
let formData = new FormData();
formData.append('file', file);
return this.http.post(this.settings.api.uploadFile, formData, {headers: { 'Content-Type': 'multipart/form-data'} })
.catch((error:any) => Observable.throw(error || 'Server error'));
}
但是请求一直都是空的:
$router->group(['prefix' => 'v1'], function () use ($router) {
$router->post('/upload', function (Request $request) use ($router) {
dd($request->all());
});
});
尝试在以下位置使用file.file
let formData = new FormData();
formData.append('file', file.file);
或发送给我console.log(file);的响应;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.