The temporary upload location xx

2020-04-26  本文已影响0人  超级笔记本

需要配置上传文件的缓存路径,并创建对应目录,三种方式
1、yml文件配置

spring:
    multipart:
      # 单个文件的最大值
      max-file-size: 100MB
      # 最大支持请求大小
      max-request-size: 100MB
      location: C:\logs\temp\

2、启动文件添加

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

3、新建配置文件

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

参考文章:https://www.jianshu.com/p/6cbe87a8ba99

上一篇 下一篇

猜你喜欢

热点阅读