关于springboot上传文件报错:The temporary upload location ***is not valid

在运行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();
     }    
}
    

猜你喜欢

转载自www.cnblogs.com/fengqian001/p/10050615.html