关于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();
     }    
}
    


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM