angular - Angular 8:服务器正在获取垃圾而不是文件数据
问题描述
我正在使用以下代码将文件上传到服务器。
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终端上没有错误消息。
解决方案
根据铬,没有身体。以下是请求标头:
选项/HTTP/1.1 主机:localhost:8000 连接:keep-alive 访问控制请求方法:PUT 来源:http://localhost:4200 用户代理: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 接受语言:en-US,en;q=0.9
谢谢你,兹维卡
推荐阅读
- r - 循环遍历绘图列表并添加到幻灯片以进行幻灯片演示
- javascript - 如果特定的 cookie 退出,onclick 窗口将不会触发
- mysql - 我在 mysql perl 中的 UPDATE 查询没有更新。我究竟做错了什么?
- javascript - 为什么 forEach 会跳过数组中尾随逗号创建的空元素?
- dynamics-crm - 有没有办法在 Dynamics 365 CRM 的 bulkEdit 表单上启用 Javascript?
- python - 用python读取的vtk文件的结构
- ruby-on-rails - 在 Rails 升级到 5.2 和 ruby 到 2.5.7 后得到未定义的方法 `prepend' for #
在 rails 升级到 5.2 版和 ruby 到 2.5.7 后,我的 rails 项目出现以下错误,我也升级了
faraday
gem,但无法解决这个问题。任何帮助都是可取的。- python - 如何从所有'中提取文本内容
' 使用 xpath 的段落标签中的标签 - python - 是否可以在 Linux 上构建 OpenCV 应用程序并在 Windows 上执行?
- c# - 您可以将 csproj 修改为一个空的实用程序项目吗?
- python - 如何从所有'中提取文本内容