錯(cuò)誤現(xiàn)象
使用springboot接收上線文件耕赘,系統(tǒng)報(bào)錯(cuò)如下:
org.springframework.web.multipart.MultipartException:
Could not parse multipart servlet request;
nested exception is java.io.IOException:
The temporary upload location [/tmp/tomcat.277464978154576567.8516/work/Tomcat/localhost/ROOT] is not valid
原因
- springboot啟動(dòng)后爽茴,會(huì)分配一個(gè)tmp目錄給springboot應(yīng)用寒矿,本例中目錄地址為:/tmp/tomcat.277464978154576567.8516/
- 但是操作系統(tǒng)會(huì)定期清除tmp文件夾蹋半,時(shí)間長了以后鹦聪,這個(gè)文件夾被刪掉以后账阻,springboot就找不到這個(gè)目錄了,就會(huì)報(bào)錯(cuò)
解決方案
在application.yml里面手工指定臨時(shí)文件夾泽本,保證數(shù)據(jù)不會(huì)被刪掉
spring:
http:
multipart:
location: /data/upload_tmp
若是使用application.properties文件淘太,則使用:
spring.http.multipart.location=/data/upload_tmp