错误信息:the temporary uplaod location [ *** ] is not valid
错误原因:在springboot项目启动后 系统会在‘/temp’目录下创建几个目录 用于上传文件。长时间运行后centos对‘/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();
}
}