Spring Boot——多文件上传大小超限问题解决

org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field fileName exceeds its maximum permitted size of 1048576 bytes.

Spring Boot默认文件上传大小为2M,多文档上传中总是出现文件大小超出限度

 

解决方法:

a、在application.properties文件中设置文件大小

# Single file max size  
multipart.maxFileSize=50Mb
# All files max size  
multipart.maxRequestSize=50Mb

  但是,事实证明此种方法不能够解决以上问题

b、在启动类App.class文件中配置Bean来设置文件大小

复制代码

import javax.servlet.MultipartConfigElement;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@Configuration
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        SpringApplication.run(App.class, args);
    }
    
    /**  
     * 文件上传配置  
     * @return  
     */  
    @Bean  
    public MultipartConfigElement multipartConfigElement() {  
        MultipartConfigFactory factory = new MultipartConfigFactory();  
        //单个文件最大  
        factory.setMaxFileSize("10240KB"); //KB,MB  
        /// 设置总上传数据总大小  
        factory.setMaxRequestSize("102400KB");  
        return factory.createMultipartConfig();  
    }  
}

 

你可能感兴趣的:(springboot,java)