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。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM