上传文件报错java
java.io.IOException: The temporary upload location [/tmp/tomcat.4836362739890928439.2000/work/Tomcat/localhost/base] is not valid
上传文件存放临时目录找不到致使错误spring
参考https://blog.csdn.net/zdyueguanyun/article/details/79271300 初始化SpringBoot的Bean:MultipartConfigElement。指定上传临时目录路径centos
@Configuration public class CommonConfiguration implements Serializable { // Spring Boot上传须要指定一个临时文件目录,不然上传会报错 [@Bean](https://my.oschina.net/bean) public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); String dirName = "springboot-upload-temp"; String localTempFileDir = System.getProperty("user.home") + File.separator + dirName; File dir = new File(localTempFileDir); if (!dir.exists()) { dir.mkdirs(); } factory.setLocation(localTempFileDir); return factory.createMultipartConfig(); } }
[ew119@VM_4_13_centos springboot-upload-temp]$ pwd /home/ew119/springboot-upload-temp