我使用了NGX-formly的教程,了解如何将文件添加到表单中
链接到教程:formly-js.github.io
这些文件被添加为表单的JSON的一部分。当使用console.log()在后端打印对象时,它看起来像这样:
{“file”:{“0”:{}
当console.log‘在前台运行时,它会给出这样的结果:[

和
[

我如何在我的Express/Node.js后端解析文件?我试过使用multer,但由于它只支持“多部分/formdata”,所以不起作用。
发布于 2018-08-21 22:20:07
查看nodejs的multer包
在安装了它并检查了示例之后,在服务上使用以下代码:
public upload(file: File){
let body = new FormData();
body.append('uploadfield',file); //uploadfield is the name of the item in formdata you picked at multer, I think its 'file' on defualt.
return new Promise(resolve => {
this.http.post("http://api-endpoit",body).subscribe(data => {
resolve(data);
}, err => {
alert(err); //or whatever you want to handle error
});
});
}在组件上:(我假设文件是私有字段-就像console.log(this.file)一样)
upload() {
this.uploadService.upload(this.file).then(res => {
if(res['success']) {
....
}
});https://stackoverflow.com/questions/51950276
复制相似问题