Increase HTTP Post maxPostSize in Spring Boot

后端 未结 14 2173
无人共我
无人共我 2020-11-28 06:48

I\'ve got a fairly simple Spring Boot web application, I have a single HTML page with a form with enctype=\"multipart/form-data\". I\'m getting this error:

相关标签:
14条回答
  • 2020-11-28 07:40

    from documentation: https://spring.io/guides/gs/uploading-files/

    Tuning file upload limits

    When configuring file uploads, it is often useful to set limits on the size of files. Imagine trying to handle a 5GB file upload! With Spring Boot, we can tune its auto-configured MultipartConfigElement with some property settings.

    Add the following properties to your existing src/main/resources/application.properties:

    spring.http.multipart.max-file-size=128KB

    spring.http.multipart.max-request-size=128KB

    The multipart settings are constrained as follows:

    • spring.http.multipart.max-file-size is set to 128KB, meaning total file size cannot exceed 128KB.

    • spring.http.multipart.max-request-size is set to 128KB, meaning total request size for a multipart/form-data cannot exceed 128KB.

    0 讨论(0)
  • 2020-11-28 07:44

    In application.properties file write this:

    # Max file size.
    spring.http.multipart.max-file-size=1Mb
    # Max request size.
    spring.http.multipart.max-request-size=10Mb
    

    Adjust size according to your need.


    Update

    Note: As of Spring Boot 2, however you can now do

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

    Appendix A. Common application properties - Spring

    0 讨论(0)
提交回复
热议问题