【发布时间】:2019-06-02 04:13:45
【问题描述】:
我在将多个文件从 angular 前端发送到 spring-boot 后端时遇到问题。我已经尝试了堆栈和网络中的所有内容,但我找不到答案。这是我的代码:
角度: .ts 文件:
submit(){
this.uploadedFiles = this.uploadedFiles.map(item => {
let formData = new FormData();
return formData.append('file',item,item.name);
});
this.service.postFile(this.uploadedFiles).subscribe(result => {
console.log(result);
})
}
this.uploadedFiles 以某种方式未定义 FormData 类型?
服务文件:
postFile(files: any): Observable<string>{
return this.http.post('/id/file', files, {responseType:'text'});
}
弹簧控制器:
@PostMapping(value = "/file")
private String newFile(@RequestBody List<MultipartFile> mf) {
return "error";
}
在调试器内部,mf 列表为 null。
主要问题是对于 1 个文件(当我只使用 MultipartFile 时),我的代码可以正常工作。
我正在使用 PrimeNG 的 p-fileupload 和自定义上传事件。
【问题讨论】:
标签: angular spring file-upload