Spring Boot 上传文件 报错 : The temporary upload location is valid

Java 新民 9089℃ 已收录 3评论

在项目开发中,一直是正常的,上传了个文件突然就报错了,报错信息如下:

    Caused by: java.io.IOException: The temporary upload location [C:\Users\zxm\AppData\Local\Temp\tomcat.8572785615189560421.8080\work\Tomcat\localhost\ROOT] is not valid
    at org.apache.catalina.connector.Request.parseParts(Request.java:2776)
    at org.apache.catalina.connector.Request.parseParameters(Request.java:3176)
    at org.apache.catalina.connector.Request.getParameter(Request.java:1110)
    at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:70)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.cloud.sleuth.instrument.web.TraceFilter.doFilter(TraceFilter.java:150)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:107)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    ... 12 common frames omitted

经过一番辛苦的查找,原来是spring boot 内部上传文件临时存储路径不存在了,现在有两种办法:

第一种:项目重启,自动重新生成临时存储路径

第二种:注入一个Bean,手动添设置下临时存储路径,代码如下:

    @Bean  
    MultipartConfigElement multipartConfigElement() {  
       MultipartConfigFactory factory = new MultipartConfigFactory();  
       factory.setLocation("d://temp");  
       return factory.createMultipartConfig();  
    }

项目重启后发现没有问题了,至此,上传问题解决啦。

本站文章如未注明,均为原创丨本网站采用BY-NC-SA协议进行授权,转载请注明转自:https://www.snowruin.com/?p=1728
喜欢 (4)or分享 (0)
发表我的评论
取消评论
表情 代码 贴图 加粗 链接 私信 删除线 签到

Hi,请填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(3)条精彩评论。
  1. 祝博主脱单发财
    122018-12-07 10:15 回复| Google Chrome 70.0.3538.110| unknow
    • 新民
      哈哈,谢谢啦
      新民2018-12-13 15:58 回复| Google Chrome 55.0.2883.87| Windows 7 x64
  2. 好吧,我试下
    122018-12-07 10:14 回复| Google Chrome 70.0.3538.110| unknow