簡體   English   中英

從LUMEN用FormData在Angular中進行POST時請求為空

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM