当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
SpringBoot搭建的项目上传文件时提示The temporary upload location ***is not valid
生活随笔
收集整理的这篇文章主要介绍了
SpringBoot搭建的项目上传文件时提示The temporary upload location ***is not valid
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
系统环境CentOS 7 + Java 8
SpringBoot内置的Tomcat启动时创建临时目录保存上传缓冲文件,但CentOS会定期清理 默认的临时文件目录(一般都在/tmp下)
解决方案:
一、修改tomcat临时目录
1.1可以采用配置文件的方式(server.tomcat.basedir=/tmp/tomcat);
1.2注入配置bean
@Configuration public class MultipartConfig {/*** 文件上传临时路径*/@BeanMultipartConfigElement multipartConfigElement() {MultipartConfigFactory factory = new MultipartConfigFactory();String location = System.getProperty("user.dir") + "/data/tmp";File tmpFile = new File(location);if (!tmpFile.exists()) {tmpFile.mkdirs();}factory.setLocation(location);return factory.createMultipartConfig();} }二、修改CentOS的临时目录配置文件,不要清理指定目录
修改 /usr/lib/tmpfiles.d/tmp.conf
# 添加一行
x /tmp/tomcat.*
总结
以上是生活随笔为你收集整理的SpringBoot搭建的项目上传文件时提示The temporary upload location ***is not valid的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 薪资6-8K,却收到了85份简历,今年求
- 下一篇: Spring中出现:“Failed to