[轉]Spring Boot修改最大上傳文件限制:The field file exceeds its maximum permitted size of 1048576 bytes.


來源: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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM