先表明一下問題,我后端一個springboot小專案,前端是vue+axios 上傳excel檔案的小功能。
btn1: function (e) {
if (!this.fileUpFlag) {
alert("請正確選擇上傳檔案!");
} else {
this.msg2 = "檔案正在決議中請稍等";
let formData = new FormData();
// console.log(this.file)
formData.append('file', this.file);
let config = {
headers: {
'Content-Type': 'multipart/form-data'
}
};
axios
.post("/excelUp", formData, config)
.then(response => {this.total = response.data.total;
this.errorIf = response.data.errorIf;
this.successSum = response.data.successSum;
this.errorSum = response.data.errorSum;
this.msg2 = "檔案決議完成!上傳資料總量:" + this.total + " 成功執行數量:" + this.successSum + " 失敗數量:" + this.errorSum
})
.catch(function (error) {
console.log(error)
});
}
e.preventDefault()
}
@ResponseBody
@PostMapping("/excelUp")
public ExcelAnalyzeResult excelUp(@RequestParam("file") MultipartFile multipartFile) {
try {
return rootService.addUserExcel(multipartFile.getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

在本地跑的時候,用chrome和火狐 360安全瀏覽器測驗均無問題。部署到服務器上之后,chrome瀏覽器出現了問題,火狐和360均無問題。chrome瀏覽器只有在服務器專案每次啟動后,第一次才能順利上傳excel,之后點擊十幾次偶爾能成功上傳決議一次。這是前后端報的錯誤。
前端:Failed to load resource: the server responded with a status of 400 ()
studentAddByExcel:149 Error: Request failed with status code 400
at e.exports (spread.js:25)
at e.exports (spread.js:25)
at XMLHttpRequest.l.<computed> (spread.js:25)
后端:2020-04-20 22:37:35.064 WARN 4708 --- [-nio-443-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present]
搞了一天了 百度也解決不來,求大佬幫忙看看
uj5u.com熱心網友回復:
去掉你的請求頭換成這三個cache: false, processData: false,contentType: false,uj5u.com熱心網友回復:
你好,問題還是存在,但還是感謝回復。這是谷歌和火狐的截圖,谷歌點個十幾次請求能成功一次,這是最讓我搞不明白的。
uj5u.com熱心網友回復:
在本地測驗你的方法也是 三個瀏覽器均無例外,就是一旦部署到華為的服務器上,chrome瀏覽器就開始 上傳失敗,火狐和360均無例外轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/87432.html
標籤:Java EE
下一篇:佇列資料型別定義問題
