所以我真的很难让文件上传到工作。我不认为这会像以前那样具有挑战性。
因此,我将从简单的HTML元素开始:
<input type="file" id="server-avatar-file" className="file-input" accept=".jpg,.jpeg,.png" onChange={this.handleChange} style={{position: "absolute", top: "0px", left: "0px", width: "100%", height: "100%", opacity: "0", cursor: "pointer"}} />这是我提交的表格数据:
handleSubmit = (event) => {
event.preventDefault();
axios.post('/api/v1/testing/upload',
this.state.file)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
};我用过勤杂工,我能想到的都有。
然而,我相信问题是源于我的前端,没有发送所有正确的信息给我的后端。
这就是this.state.file的价值所在:

我理解Node中的bodyParser不解析文件类型,我不熟悉如何在服务器上解析它们。我想通过上传到我的文件系统来测试它,但是我想转移到生产中的CDN,所以让我很容易做的事情将是伟大的!
发布于 2016-11-19 05:04:15
busboy、multer和其他多部分解析模块需要正确格式化的多部分/表单数据请求。用axios发送这样的请求的一个简单方法是传递一个FormData实例,而不是作为数据参数的原始File或Blob实例。
https://stackoverflow.com/questions/40689205
复制相似问题