Spring Boot做文件上传时出现了The field file exceeds its maximum permitted size of 1048576 bytes.错误,显示文件的大小超出了允许的范围。查看了官方文档,原来Spring Boot工程嵌入的tomcat限制了请求的文件大小,这一点在Spring Boot的官方文档中有说明,原文如下

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。要更改这个默认值需要在配置文件(如application.properties)中加入两个配置

  1. multipart.maxFileSize = 10Mb

  2. multipart.maxRequestSize=100Mb

multipart.maxFileSize=10Mb是设置单个文件的大小, multipart.maxRequestSize=100Mb是设置单次请求的文件的总大小

如果是想要不限制文件上传的大小,那么就把两个值都设置为-1就行啦

*****************************后续更新******************************如果有误,请查看文末提示官方文档哈

Spring Boot1.4版本后配置更改为:

  1. spring.http.multipart.maxFileSize = 10Mb

  2. spring.http.multipart.maxRequestSize=100Mb

Spring Boot2.0之后的版本配置修改为:

  1. spring.servlet.multipart.max-file-size = 10MB

  2. spring.servlet.multipart.max-request-size=100MB

详情参考Spring Boot官方文档,感谢评论的小伙伴给出的建议更新提示。

**************

重要:如果以上的配置有误,尝试将=更改为:或者将Mb单位更改为MB,Spring Boot版本迭代很快,请以Spring Boot的官方文档为准。

Spring Boot各版本文档地址(比较齐全)

https://docs.spring.io/spring-boot/docs/

进入reference/html/目录就是了。

FAQ:The field file exceeds its maximum permitted size of 1048576 bytes.相关推荐

  1. 解决问题:The field file exceeds its maximum permitted size of 1048576 bytes

    错因描述: springboot项目使用文件上传失败,上传是个Excel文件,大小为1.35M The field file exceeds its maximum permitted size of ...

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

    一.简介 Spring Boot做文件上传时出现了The field file exceeds its maximum permitted size of 1048576 bytes.错误, 显示文件 ...

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

    问题描述 使用Springboot上传流时,出现了下面的异常 org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededExce ...

  4. 上传文件过大时,报The field file exceeds its maximum permitted size of 1048576 bytes问题

    该问题是因为后台默认的接收文件的最大尺寸是1M,当上传的单张图片大小超过1M时,后台接收就会有问题,就会出现这种问题 解决方案:1.在前端直接压缩为1M以下的图片 2.在后台进行图片可接收尺寸的限制 ...

  5. Spring Boot 批量上传: The field files exceeds its maximum permitted size of 1048576 bytes.

    Spring Boot 批量上传异常: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededExcep ...

  6. 解决因nginx配置导致文件上传失败的问题 The filed file exceeds its maximum permitted size of 1048576 bytes

    解决因nginx配置问题导致文件上传失败的问题 1.问题背景 2.问题截图 3.问题分析 4.问题解决(修改nginx的配置) 5.解决之后的"后遗症"(截图) 6.分析并解决&q ...

  7. SpringBoot上传文件报错The field multiFile exceeds its maximum permitted size of 1048576 bytes.

    异常 org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field multiFile e ...

  8. org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds i

    org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds i ...

  9. mycat 启动失败 The specified size exceeds the maximum representable size JVM exited while loading the a

    错误信息: [root@server1 bin]# ./mycat console Running Mycat-server... wrapper  | --> Wrapper Started ...

  10. InnoDB: Error: log file .\ib_logfile0 is of different size 0 10485760 bytes

    启动WAMP Server的时候报例如以下的错误: 140618 23:12:32 [Note] Plugin 'FEDERATED' is disabled. 140618 23:12:32 Inn ...

最新文章

  1. Html转义字符列表
  2. 解决父级元素高度塌陷问题的方法
  3. C#里调用带输出参数的存储过程
  4. .net Csharpt C# UDP 异步发送信息 代码实例
  5. discuz nt 安装,完全攻略。
  6. arduino无源蜂鸣器歌曲编码_Arduino与无源蜂鸣器
  7. java登陆界面工具_javaee编写登陆界面
  8. Android的debug.keystore拒绝访问导致的生成异常及解决方案
  9. 我终于知道公司前端为啥不加班了…
  10. 配色神器,轻松解决你所有的配色难题!
  11. mysql 时间戳 bigint_MySQL时间类型datetime、bigint及timestamp的查询效率
  12. MDataTable属性RecordsAffected新应用:WebService与Json交互的记录总数
  13. 基于python的opencv摄像头采集
  14. Android虚拟电脑,如何让你的android模拟器连接上你电脑的网络
  15. ID3、C4.5决策树算法的Python实现(注释详细)
  16. 【miscellaneous】视频浓缩摘要简介
  17. 信用评分卡模型开发中双峰分布原因及解决方案
  18. 【电子学会】2019年09月图形化一级 -- 猫捉老鼠
  19. js复制、粘贴完整实例代码
  20. 计算机中丢失ubiorbitapi,我的刺客信条出现无法启动此程序,因为计算机中丢失ubiorbitapi_r2_loader.dll,,怎么处理。。...

热门文章

  1. UVA - 10400 Game Show Math
  2. Biobank genetic data探析(三)
  3. 开发中使用第三方工具/服务
  4. json格式的php文件怎么打开,json格式是什么?json格式文件怎么打开?
  5. Win10能聊微信不能上网的解决方案
  6. IPS与IDS部署场景
  7. Linux 文件同步工具——rsync
  8. 奶头乐理论和二八定律和马太效应
  9. 基于jsp的学生培训管理系统
  10. 2017年 外牌转沪牌 攻略 (沪南路车管所)