我想在从前端到后端的 fetch 调用中传递 aJSON Object和 a CSV file。headerIngestion是 JSON,我将文件保存在csv状态中let formData = new FormData();formData.append('header', headerIngestion);formData.append('file', this.state.csv);fetch('http://localhost:8080/...', { method: 'POST', body: formData }) .then ...到目前为止,我的服务器使用 SpringBoot,因为最初我只通过了 csv 文件。@PostMapping(URL)public String ingestDataFile(@RequestParam("file") MultipartFile file) { if (!file.isEmpty()) { byte[] bytes; try { bytes = file.getBytes(); String completeData = new String(bytes); System.out.println(completeData); } catch (IOException e) { e.printStackTrace(); } } return "something";}我需要做什么才能分别访问JSON和file?
1 回答
温温酱
TA贡献1752条经验 获得超4个赞
经过大量玩耍后,这奏效了
public String ingestDataFile(@RequestPart("header") String json, @RequestPart("file") MultipartFile file) {
添加回答
举报
0/150
提交
取消