SpringBoot2.x文件上传出错 maximum permitted size of 1048576 bytes

Posted dingwen_blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot2.x文件上传出错 maximum permitted size of 1048576 bytes相关的知识,希望对你有一定的参考价值。

问题描述:

在搭建minio服务时,文件上传出错。

Caused by: java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field multipartFile exceeds its maximum permitted size of 1048576 bytes.

原因分析:

Spring Boot工程嵌入的tomcat限制了请求的文件大小
65.5 Handling Multipart File Uploads
Spring Boot embraces the Servlet 3 javax.servlet.http.Part API to support uploading files. By default Spring Boot configures Spring MVC with a maximum file of 1Mb per file and a maximum of 10Mb of file data in a single request. You may override these values, as well as the location to which intermediate data is stored (e.g., to the /tmp directory) and the threshold past which data is flushed to disk by using the properties exposed in the MultipartProperties class. If you want to specify that files be unlimited, for example, set the multipart.maxFileSize property to -1.The multipart support is helpful when you want to receive multipart encoded file data as a @RequestParam-annotated parameter of type MultipartFile in a Spring MVC controller handler method.
个文件的配置最大为1Mb,单次请求的文件的总数不能大于10Mb。要更改这个默认值需要在配置文件中加入两个配置

spring:
  servlet:
    multipart:
      enabled: true
      max-file-size: 2048MB # 单个文件最大限制
      max-request-size: 3000MB # 整体请求大小限制

以上是关于SpringBoot2.x文件上传出错 maximum permitted size of 1048576 bytes的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot2.x文件上传大小单位设置

SpringBoot2.x + Minio 文件服务器 简单使用

Spring Boot 2.x 实现文件上传与下载

Eclipse搭建springboot项目文件上传

SpringBoot WebUploader大文件分片上传

springboot2.X+maven+mybatis+shiro+redis