繁体   English   中英

Angular 8:服务器正在获取垃圾而不是文件数据

[英]Angular 8: Server is getting garbage instead of file data

我正在使用以下代码将文件上传到服务器。

import {HttpClient} from '@angular/common/http';

fileChange(event) {
let fileList: FileList = event.target.files;
let file: File = fileList[0];
let body: FormData = new FormData();
body.append('uploadFile', file, file.name);
this.http.put('http://localhost:8000', body).subscribe (data => {console.log ('response',data);});
}

我正在使用我开发的 HTTP 服务器,所以我可以看到来自客户端的所有数据。 出于某种原因,在 PUT 之后,服务器正在获取垃圾而不是文件中的数据。 chrome终端上没有错误信息。

根据铬,没有身体。 以下是请求标头:

OPTIONS / HTTP/1.1 Host: localhost:8000 Connection: keep-alive Access-Control-Request-Method: PUT Origin: http://localhost:4200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit /537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36 Accept: / Sec-Fetch-Site: same-site Sec-Fetch-Mode: cors Referer: http://localhost:4200/timing Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9

谢谢你,兹维卡

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM