zl程序教程

您现在的位置是:首页 >  后端

当前栏目

SpringBoot设置MultipartFile文件大小限制

SpringBoot 设置 限制 文件大小
2023-09-11 14:20:10 时间

原文链接: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();
}

}