报错信息:

  1. "localizedMessage": "The temporary upload location [C:\\Users\\YY\\AppData\\Local\\Temp\\tomcat.1793760262133383655.8081\\work\\Tomcat\\localhost\\ROOT] is not valid",
  2. "message": "The temporary upload location [C:\\Users\\YY\\AppData\\Local\\Temp\\tomcat.1793760262133383655.8081\\work\\Tomcat\\localhost\\ROOT] is not valid",
  3. "suppressed": []
  1. import org.springframework.boot.web.servlet.MultipartConfigFactory;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import javax.servlet.MultipartConfigElement;
  5. import java.io.File;
  6. /**
  7. * 配置文件上传临时路径,解决上传报错的问题
  8. * localizedMessage:
  9. * "The temporary upload location
  10. * [C:\Users\YY\AppData\Local\Temp\tomcat.3305898259059649641.8083\work\Tomcat\localhost\ROOT]
  11. * is not valid"
  12. */
  13. @Configuration
  14. public class MultipartConfig {
  15. /**
  16. * 文件上传临时路径
  17. */
  18. @Bean
  19. MultipartConfigElement multipartConfigElement() {
  20. MultipartConfigFactory factory = new MultipartConfigFactory();
  21. String location = System.getProperty("user.dir") + "/data/tmp";
  22. File tmpFile = new File(location);
  23. if (!tmpFile.exists()) {
  24. tmpFile.mkdirs();
  25. }
  26. factory.setLocation(location);
  27. return factory.createMultipartConfig();
  28. }
  29. }