【发布时间】:2018-08-20 19:02:31
【问题描述】:
我想在从前端到后端的 fetch 调用中传递 JSON Object 和 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?
【问题讨论】:
标签: javascript java json reactjs fetch