SpringBoot设置MultipartFile文件大小限制

原文链接:https://blog.csdn.net/qq_36514766/article/details/102500310

package com.gdd.videos.mini_api.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import javax.servlet.MultipartConfigElement;
import java.io.IOException;

/**
* @author zhangh
* @version V1.0.0
* @projectName parent
* @title IndexSwaggerConfig
* @package com.gdd.videos.mini_api.common
* @date 2019/9/11 15:19
* @explain 项目启动时默认打开swagger页面
*/
@Configuration
public class IndexSwaggerConfig {

/**
* 配置文件上传大小
*/
@Bean
public MultipartConfigElement multipartConfigElement(){
MultipartConfigFactory factory = new MultipartConfigFactory();
// 单个数据大小 10M
factory.setMaxFileSize("10240KB");
/// 总上传数据大小 10M
factory.setMaxRequestSize("10240KB");
return factory.createMultipartConfig();
}

}

posted @ 2020-09-20 16:04  枫树湾河桥  阅读(7427)  评论(0编辑  收藏  举报
Live2D