我想在從前端到后端的 fetch 調(diào)用中傳遞 aJSON Object和 a CSV file。headerIngestion是 JSON,我將文件保存在csv狀態(tài)中l(wèi)et formData = new FormData();formData.append('header', headerIngestion);formData.append('file', this.state.csv);fetch('http://localhost:8080/...', { method: 'POST', body: formData }) .then ...到目前為止,我的服務(wù)器使用 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貢獻(xiàn)1752條經(jīng)驗 獲得超4個贊
經(jīng)過大量玩耍后,這奏效了
public String ingestDataFile(@RequestPart("header") String json, @RequestPart("file") MultipartFile file) {
添加回答
舉報
0/150
提交
取消