来源:http://blog.csdn.net/awmw74520/article/details/70230591

SpringBoot做文件上传时出现了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)中加入两个配置

需要设置以下两个参数

multipart.maxFileSize
multipart.maxRequestSize

Spring Boot 1.3.x或者之前

multipart.maxFileSize=100Mb
multipart.maxRequestSize=1000Mb

Spring Boot 1.4.x或者之后

spring.http.multipart.maxFileSize=100Mb
spring.http.multipart.maxRequestSize=1000Mb

很多人设置了multipart.maxFileSize但是不起作用,是因为1.4版本以上的配置改了,详见官方文档:spring boot 1.4

[转]Spring Boot修改最大上传文件限制:The field file exceeds its maximum permitted size of 1048576 bytes.的更多相关文章

  1. Spring Boot:The field file exceeds its maximum permitted size of 1048576 bytes

    错误信息:The field file exceeds its maximum permitted size of 1048576 bytes原因是因为SpringBoot内嵌tomcat默认所能上传 ...

  2. Spring Boot 在接收上传文件时,文件过大异常处理问题

    Spring Boot 在接收上传文件时,文件过大时,或者请求过大,spring内部处理都会抛出异常,并且捕获不到. 虽然可以通过调节配置,增大 请求的限制值. 但是还是不太方便. 之所以捕获不到异常 ...

  3. 【Spring Boot】关于上传文件例子的剖析

    目录 Spring Boot 上传文件 功能实现 增加ControllerFileUploadController 增加ServiceStorageService 增加一个Thymeleaf页面 修改 ...

  4. Spring Boot 使用 ServletFileUpload上传文件失败,upload.parseRequest(request)为空

    使用Apache Commons FileUpload组件上传文件时总是返回null,调试发现ServletFileUpload对象为空,在Spring Boot中有默认的文件上传组件,在使用Serv ...

  5. spring boot 2.X上传文件限制大小

    Spring Boot 1.3.x multipart.maxFileSize multipart.maxRequestSize Spring Boot 1.4.x and 1.5.x spring. ...

  6. Spring中servletFileUpload完成上传文件以及文本的处理

    JSP: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...

  7. Windows服务器修改网站上传文件的大小限制

    ASP程序 方法一: 修改该网站的的最大上传文件的大小限制 在Windows server上会出现上传大小受限制的问题,这是由于windows server的IIS管理器做了限制所致,IIS默认设置是 ...

  8. Spring Boot +Bootstrap 图片上传与下载,以及在bootstrap-table中的显示

    1.前台上传: <input type="file" name="file" id="file"> 2.后台的接收与处理: St ...

  9. Spring使用ajax异步上传文件

    单文件上传 <!-- 创建文件选择框 --> 文件上传 :<input type="file" id="file" name="fi ...

随机推荐

  1. HTTP请求头信息

    常用请求头 User-Agent : 浏览器信息Host : 服务区域名Referer : 通过哪里的链接过来的Origin : 跨域相关Content-Type : POST和PUT请求的数据类型C ...

  2. DCL单例模式

    我们第一次写的单例模式是下面这样的: public class Singleton { private static Singleton instance = null; public static ...

  3. linux mount -t -o 用法

    挂接命令(mount) 首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用到的. 命令格式: mount [-t vfstype] [-o optio ...

  4. signal & slot

    The Qt signals/slots and property system are based on the ability to introspect the objects at runti ...

  5. spring中BeanFactory和FactoryBean的区别

    共同点: 都是接口 区别: BeanFactory 以Factory结尾,表示它是一个工厂类,用于管理Bean的一个工厂 在Spring中,所有的Bean都是由BeanFactory(也就是IOC容器 ...

  6. MicroPython的开发板

    比如: pyboard micro:bit ESP8266/ESP32 stm32等等 什么是pyboard? pyboard是官方的MicroPython微控制器板,完全支持软件功能.硬件有: ST ...

  7. Codeforces Educational Codeforces Round 57 题解

    传送门 Div 2的比赛,前四题还有那么多人过,应该是SB题,就不讲了. 这场比赛一堆计数题,很舒服.(虽然我没打) E. The Top Scorer 其实这题也不难,不知道为什么这么少人过. 考虑 ...

  8. Oracle 闪回

    Oracle 闪回特性(FLASHBACK DATABASE) 本文来源于:gerainly 的<Oracle 闪回特性(FLASHBACK DATABASE) > -========== ...

  9. Confluence 6 使用 WebDAV 客户端来对页面进行操作

    下面的部分告诉你如何在不同的系统中来设置原生的 WebDAV 客户端,这个客户端通常显示在你操作系统的文件浏览器中,例如,Windows 的 Windows Explorer 或者 Linux 的 K ...

  10. Swift 新增fileprivate 详解

    以前项目中只要用了private  那么在同一个文件同一个类中还是能访问的(比如一个类中写了一个extension) swift3.0现在不行了 新增了一个fileprivate 的访问控制 以前的p ...