Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location

时间:2021-10-23 23:07:32

 

spring-boot项目,生产环境运行一段时间后,上传图片报错,如下:

threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.2982178524163133296.8080/work/Tomcat/localhost/ssc] is not valid] with root cause] |
java.io.IOException: The temporary upload location [/tmp/tomcat.2982178524163133296.8080/work/Tomcat/localhost/ssc] is not valid

 

解决方案:添加指定目录

@Configuration
public class MultipartConfig {
    /**
     * 文件上传临时路径
     */
    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setLocation("/data/dubbo/cache");
        return factory.createMultipartConfig();
    }

}