首页 > 基础资料 博客日记
spring boot 上传文件报错:java.io.IOException: The temporary upload location [/tmp/tomcat.xxx] is not valid
2023-07-27 19:14:59基础资料围观522次
springboot 项目上传文件报错:java.io.IOException: The temporary upload location [/tmp/tomcat.xxx] is not valid
项目突然发现图片上传的接口有问题,无法上传,提示java.io.IOException: The temporary upload location [/tmp/tomcat.7538204303517105479.8899/work/Tomcat/localhost/main_service] is not valid的异常。
查看日志
2019-06-05 11:04:35.904 [http-nio-8899-exec-10] ERROR o.a.c.c.C.[.[.[/main_service].[dispatcherServlet] Servlet.service() for servlet [dispatcherServlet] in context with path [/main_service] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.7538204303517105479.8899/work/Tomcat/localhost/main_service] is not valid] with root cause
java.io.IOException: The temporary upload location [/tmp/tomcat.7538204303517105479.8899/work/Tomcat/localhost/main_service] is not valid
at org.apache.catalina.connector.Request.parseParts(Request.java:2821)
at org.apache.catalina.connector.Request.getParts(Request.java:2754)
at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1098)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:94)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.(StandardMultipartHttpServletRequest.java:87)
at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:87)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1175)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1010)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocolConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpointSocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThreadWrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
错误原因:
/tmp/tomcat.117985270780171125.80/work/Tomcat/localhost/bcp 文件夹不存在
错误分析:
springboot在启动的时候会创建一个tmp的临时文件用来存放一下临时的文件信息等内容
tmp文件夹 有个特性 ,就是在10天内没有进行操作,该文件夹内的文件夹和文件等就会自动被清除,导致一些文件丢失。
在进行文件上传的时候会先将文件临时存放在/tmp/tomcat.126054745504544145.8011/work/Tomcat/localhost/pay 下(备注:这个对应的是我自己的项目路径,项目不同路径肯定不相同)
解决方法:
方法一:直接重新启动项目即可解决(原因是日志占满磁盘后[请清理空间和检查磁盘],临时目录不再创建)
方法二:在springboot的配置文件里加个配置
server.tomcat.basedir=/app/temp
这个路径需要你在Linux根目录下下建个/app/temp文件
方法三:指定上传文件临时的路径(从根本解决),如下
//在启动类里面添加MultipartConfigElement 配置类
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setLocation("/pttms/tmp");//指定临时文件路径,这个路径可以随便写
return factory.createMultipartConfig();
}
指定好临时路径后还需要在Linux环境上创建对应的文件夹,在重启项目
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
标签:
上一篇:javaScript:表达式转二叉树
下一篇:Java的基础语法01