Spring boot 上傳文件,突然出現異常:
org.springframework.web.multipart.MultipartException: Failed to parsemultipart servlet request; nested exception is java.io.IOException:The temporary upload location [/tmp/tomcat.6561926259726375802.9096/work/Tomcat/localhost/ROOT] is not valid
原因是:springboot啓動之後會在 /tmp 目錄創建文件夾等內容,但是如果十天之內都沒有發生文件上傳操作,系統會自動將臨時文件給清理掉,導致後續再上傳文件會找不到臨時目錄報錯
解決方案:在application.properties配置文件中添加上傳文件的臨時目錄:
server.tomcat.basedir=\tmp\uploadfile
經過配置後,再次上傳文件,就可以直接上傳了。