欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SpringBoot1.x升级SpringBoot2.x踩坑之文件上传大小限制

程序员文章站 2023-02-15 15:08:16
SpringBoot1.x升级SpringBoot2.x踩坑之文件上传大小限制 ......

springboot1.x升级springboot2.x踩坑之文件上传大小限制

前言

lz最近升级springboo框架到2.1.6,踩了一些坑,这里介绍的是文件上传大小限制。

升级前
  #文件上传配置 1.5.9
   spring:
       http:
          multipart:
              enabled: true
              max-file-size: 100mb
              max-request-size:100mb
升级后
  ##文件上传配置 2.x
   spring:
     servlet:
       multipart:
         enabled: true
         max-file-size: 100mb
         max-request-size: 100mb
原因

我们可以从源码分析,找到springboot的相关源码——multipartproperties

package org.springframework.boot.autoconfigure.web.servlet;

import javax.servlet.multipartconfigelement;
import org.springframework.boot.context.properties.configurationproperties;
import org.springframework.boot.web.servlet.multipartconfigfactory;
import org.springframework.util.stringutils;

@configurationproperties(
    prefix = "spring.servlet.multipart",
    ignoreunknownfields = false
)
public class multipartproperties {
    private boolean enabled = true;
    private string location;
    private string maxfilesize = "1mb";
    private string maxrequestsize = "10mb";
    private string filesizethreshold = "0";
    private boolean resolvelazily = false;
    .........
}

上面是springboot2.x源码,从上面可以看出,maxfilesize,即最大文件大小,默认被限制为1mb,maxrequestsize即最大请求大小,默认被限制为10mb。该类的注解中prefix=spring.servlet.multipart。