SpringBoot 配置文件上传大小

Spring Boot 设置文件上传大小的实现两种方式。

第一种:通过application.properties 配置文件实现:

spring.http.multipart.maxFileSize=10MB
spring.http.multipart.maxRequestSize=10MB

maxFileSize:单个文件大小

maxRequestSize:总上传文件大小

第二种:通过@Configuration文件上传配置类,我采用了该种方式:

import javax.servlet.MultipartConfigElement;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

/**
 * 文件上传配置参数
 * @author zzg
 *
 */
@Configuration
@ImportResource({"classpath:uploadFile.xml" })
public class UploadConfig {
	
	

	/**
     * 文件上传配置
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //文件最大
        factory.setMaxFileSize("50MB"); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize("60MB");
        return factory.createMultipartConfig();
    }


}

uploadFile.xml 配置文件,配置文件上传的存储根路径。



 
	
	
	
		
	
	
	

 

你可能感兴趣的:(微服务springboot)