我想在从前端到后端的 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?
温温酱
相关分类