今天使用Vue上传图片,一直报—>The field file exceeds its maximum permitted size of 1048576 bytes.
百度翻译:字段文件超过1048576字节的最大允许大小。

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

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.

SpringBoot 2.X的Yml配置如下:

spring:
   servlet:
     # 上传文件大小的配置
     multipart:
       enabled: true
       # 单个数据的大小
       max-file-size: 10MB
       # 总数据的大小
       max-request-size: 10MB