How does one specify a temp directory for file uploads in Spring Boot?

前端 未结 4 1715
太阳男子
太阳男子 2021-02-01 17:42

I\'m using Spring Boot and need to let users upload files for processing. Right now, the file uploads to /home/username/git/myproject which is not great.

How do I make S

4条回答
  •  我在风中等你
    2021-02-01 18:15

    If somebody is still looking for programmatic configuration:

    @Configuration
    public class ServletConfig {
    
      @Bean
      public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) {
        final ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
        final String location = System.getProperty("java.io.tmpdir");
        final long maxFileSize = 128*1024;
        final long maxRequestSize = 128*1024;
        final MultipartConfigElement multipartConfig  = new MultipartConfigElement(location, maxFileSize, maxRequestSize, 0);
        registration.setMultipartConfig(multipartConfig);
        return registration;
      }
    
    }
    

提交回复
热议问题