【发布时间】:2018-02-26 10:23:41
【问题描述】:
我正在尝试使用Codepen 中给出的代码示例上传图片
我的状态变量中有文件内容,并通过下面提到的提交函数在控制台中获取它
_handleSubmit(e) {
e.preventDefault();
console.log(this.state.file)
payLoad = {
image: this.state.file,
}
axios({
method: 'post',
url: this.state.url+'/task',
data: payLoad,
headers: {
'content-type': 'multipart/form-data'
}
})
}
this.state.file 我的控制台结果是
File(128544)
lastModified:1508143324556
lastModifiedDate:Mon Oct 16 2017 14:12:04 GMT+0530 (India Standard Time) {}
name:"sample.png"
size:128544
type:"image/png"
webkitRelativePath:""
__proto__:File
但网络在 API 请求标头中将图像变量显示为 {},并且图像未上传。任何人都可以帮忙吗?由于我是 ReactJS 的新手,所以我在某些功能上确实遇到了麻烦,因此不得不在这里提出很多问题。
【问题讨论】:
标签: reactjs