繁体   English   中英

FormData append是附加文件后的空对象

[英]FormData append is an empty object after appending a file

这是我尝试附加并发送到服务器的文件(console.log):

...
console.log(myFile); // brings this:

File(1921512) {name: "2018-10-07_23-53-14.png", lastModified: 1538945346813, lastModifiedDate: Sun Oct 07 2018 23:54:06 GMT+0300 (Israel Daylight Time), webkitRelativePath: "", size: 1921512, …}
lastModified: 1538945346813
lastModifiedDate: Sun Oct 07 2018 23:54:06 GMT+0300 (Israel Daylight Time) {}
name: "2018-10-07_23-53-14.png"
size: 1921512
type: "image/png"
webkitRelativePath: ""
__proto__: File

我将这个文件附加如下:

let formData = new FormData();
formData.append(0, myFile);

然后我做:

console.log(formData); // FormData {}__proto__: FormData

没有附加文件。

当我尝试将其发送到服务器时,Http请求标头的内容类型不包含任何内容类型:

请求标头:

Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7,pt;q=0.6,la;q=0.5
Access-Control-Request-Headers: authorization
Access-Control-Request-Method: POST
Cache-Control: no-cache
Connection: keep-alive
Host: localhost:3000
Origin: http://localhost:8080
Pragma: no-cache
Referer: http://localhost:8080/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

我曾尝试使用实体记录此信息,但这仍然无法正常工作-无论如何服务器均未获取任何文件。

我在请求参数中添加了: transformRequest: angular.identity

暂无
暂无

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

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