The field file exceeds its maximum permitted size of 1048576 bytes.

简介: The field file exceeds its maximum permitted size of 1048576 bytes.

@[toc]

一、背景描述

本项目是个Springboot 项目,功能是要做一个文件上传,在测试时发现报错,上传的是一个 word 文件,大小是 1.25MB,报错内容如下:

Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.

详细报错内容如下图所示:

二、错误原因

SpringBoot 项目在文件上传时出现了 Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes. 的错误,显示文件的大小超出了允许的范围。原因是 SpringBoot内嵌的 tomcat 默认的所有上传的文件大小为 1MB,超出这个大小就会报错,解决这个问题需要更改以下两个默认。

multipart.maxFileSize
multipart.maxRequestSize

三、解决方案

解决方案呢,要根据SpringBoot的版本来确定,以下列举出了几种情况,可以根据自己项目的SpringBoot版本来对应:把默认的文件的大小限制修改一下即可。以下是我项目中的用到的文件大小限制,改成50MB即可满足我的需求了。

3.1 SpringBoot 1.3.x 之前

multipart.maxFileSize=50Mb
multipart.maxRequestSize=50Mb

3.2 SpringBoot 1.4.x

spring.http.multipart.maxFileSize=50Mb
spring.http.multipart.maxRequestSize=50Mb

3.3 SpringBoot 2.0.x之后

spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=50MB
配置完上述限制之后,重启项目,Bingo,搞定!!!

完结!

相关文章
PHP Allowed memory size of 134217728 bytes exhausted (tried to allocate 10489856 bytes)
PHP Allowed memory size of 134217728 bytes exhausted (tried to allocate 10489856 bytes)
117 2
|
9月前
|
max code size exceeded
max code size exceeded
93 6
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
194 0
|
10月前
|
devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 163840 free dat
devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 163840 free dat
91 0
The field file exceeds its maximum permitted size of 1048576 bytes 文件上传大小受到限制,报错!!
The field file exceeds its maximum permitted size of 1048576 bytes 文件上传大小受到限制,报错!!
838 0
记录:The field files exceeds its maximum permitted size of 1048576 bytes...【亲测有效】
记录:The field files exceeds its maximum permitted size of 1048576 bytes...【亲测有效】
1175 0
ERROR 2020 (HY000): Got packet bigger than 'max_allowed_packet' bytes
今天在测试环境发生了貌似怪异的报错,表结构如下: CREATE TABLE `test` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `step` bigint(20) NOT NULL COMMENT 'step', `da.
2785 0
Got a packet bigger than 'max_allowed_packet' bytes
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/inforstack/article/details/79867678 两种方案 临时修改 mysql>set global max_allowed_packet=524288000; 修改/etc/my.cnf 修改mysql的最大允许包大小 ,然后重启mysql服务就可以了。
1039 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等