开发者社区> Oracle中文开发者社区> 正文

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,搞定!!!

完结!

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
记录:The field files exceeds its maximum permitted size of 1048576 bytes...【亲测有效】
记录:The field files exceeds its maximum permitted size of 1048576 bytes...【亲测有效】
585 0
OutOfMemoryError系列(7): Requested array size exceeds VM limit
这是本系列的第七篇文章, 相关文章列表: OutOfMemoryError系列(1): Java heap space OutOfMemoryError系列(2): GC overhead limit exceeded OutOfMemoryError系列(3): Perm...
2629 0
Time range (447392) for take 'Take 001' is larger than maximum allowed(100000).
http://www.cnblogs.com/lopezycj/archive/2012/05/16/unity3d_tuchao.html   https://forum.unity3d.com/threads/time-range-447406-for-translation-curve-s-on-node-bone001-on-take-take-001-what-the.
1441 0
[20170607]maximum size is 50 characters
[20170607]maximum size is 50 characters.txt --//昨天有人问,使用链接http://blog.itpub.net/267265/viewspace-2140061/那样的方式连接,会出现问题.
888 0
[20120612]ORA-01450: maximum key length (3215) exceeded .txt
1.产生问题SQL> drop table t purge; Table dropped. SQL> create table t as select rownum id ,dbms_random.
859 0
Fatal error: Allowed memory size of 20971520 bytes exhausted
 PHP运行的时候出现如下错误: Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 35 bytes) in D:\zzx\APMServ5.2.0\www\htdocs\temp.php on line 21 解决方法:修改php.ini的memory_limit,改大点就行了,记得重启apache。
734 0
Maximum size of arbitrary code allowed
The LimitRequestLine directive [17] in the Apache configuration file allows the webserver to reduce the size of an HTTP request .
503 0
文章
问答
文章排行榜
最热
最新
相关电子书
更多
Large Scale Data Files,Object
立即下载
In Pursuit of Optimal Storage
立即下载
AliHB Real-Time Cold data Backup
立即下载