当前位置:网站首页>【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
2022-07-31 02:58:00 【No8g攻城狮】
本文目录
一、背景描述
本项目是个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=50Mb3.2 SpringBoot 1.4.x
spring.http.multipart.maxFileSize=50Mb
spring.http.multipart.maxRequestSize=50Mb3.3 SpringBoot 2.0.x之后
spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=50MB配置完上述限制之后,重启项目,Bingo,搞定!!!
完结!
边栏推荐
- Modbus on AT32 MCU
- STM32问题合集
- YOLOV5 study notes (3) - detailed explanation of network module
- 经典链表OJ强训题——快慢双指针高效解法
- try-catch中含return
- CorelDRAW2022 streamlined Asia Pacific new features in detail
- 4、敏感词过滤(前缀树)
- STM32CUBEMX开发GD32F303(11)----ADC在DMA模式下扫描多个通道
- 5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
- VS QT——ui不显示新添加成员(控件)||代码无提示
猜你喜欢

4、敏感词过滤(前缀树)

10. Redis implements likes (Set) and obtains the total number of likes

SQL injection Less54 (limited number of SQL injection + union injection)

YOLOV5 study notes (3) - detailed explanation of network module

公司官网建站笔记(六):域名进行公安备案并将备案号显示在网页底部

什么是分布式锁?实现分布式锁的三种方式

关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法

4. Sensitive word filtering (prefix tree)

Graphical lower_bound & upper_bound

Chapter 9 SVM实践
随机推荐
多线程下类对象的服务承诺探讨
LeetCode 每日一题 2022/7/25-2022/7/31
Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!
拒绝加班,程序员开发的效率工具集
【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
AI software development process in medical imaging field
TCP/IP四层模型
Face detection based on opencv
Hanyuan Hi-Tech 8-channel HDMI integrated multi-service high-definition video optical transceiver 8-channel HDMI video + 8-channel two-way audio + 8-channel 485 data + 8-channel E1 + 32-channel teleph
跨专业考研难度大?“上岸”成功率低?这份实用攻略请收下!
【Bank Series Phase 1】People's Bank of China
SQL注入 Less47(报错注入) 和Less49(时间盲注)
【编译原理】递归下降语法分析设计原理与实现
16、热帖排行
8. Unified exception handling (controller notifies @ControllerAdvice global configuration class, @ExceptionHandler handles exceptions uniformly)
Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
11、Redis实现关注、取消关注以及关注和粉丝列表
经典链表OJ强训题——快慢双指针高效解法
Moxa NPort device flaw could expose critical infrastructure to devastating attack
学习DAVID数据库(1)