Springboot启动很久上传文件报错Could not parse multipart servletThe temporary upload location xx is not valid

it2022-05-09  15

具体报错: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.8776548170270869740.8099/work/Tomcat/localhost/ROOT] is not valid org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location

在运行springboot时 ,长时间运行后报错 the temporary uplaod location *** is not valid 查过资料后发现是centos对‘/temp’下文件自动清理的原因。 在springboot项目启动后 系统会在‘/temp’目录下创建几个目录 用于上传文件。因此清理过‘/temp’下文件后无法上传

解决方法: 1 重启服务;

2 改变临时文件的存储路径

@Configuration public class MultipartConfig{ /** *文件临时上传路径 */ @Bean MultipartConfigElement 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(); } }

最新回复(0)