spring boot工程檔案上傳出現net::ERR_CONNECTION_ABORTED,檔案上傳失敗

來源:互聯網
上載者:User

標籤:spring   1.3   logs   不能   5.5   encode   pre   技術分享   工程檔案   

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=100Mbmultipart.maxRequestSize=1000Mb

Spring Boot 1.4.x或者之後

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

 

spring boot工程檔案上傳出現net::ERR_CONNECTION_ABORTED,檔案上傳失敗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.