zoukankan      html  css  js  c++  java
  • 上传文件异常 MultipartException

    参考自  https://blog.csdn.net/u010429286/article/details/54381705

    现象

    上传文件报错

    org.springframework.web.multipart.MultipartException

    Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException:

    org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field image exceeds its maximum permitted size of 1048576 bytes.

    分析

    通过百度发现是spring-boot上传文件是有大小限制的,可以通过配置文件修改

    解决

    查看了官方文档,原来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 = 10Mb
     
    multipart.maxRequestSize=100Mb

    multipart.maxFileSize=10Mb是设置单个文件的大小, multipart.maxRequestSize=100Mb是设置单次请求的文件的总大小

    如果是想要不限制文件上传的大小,那么就把两个值都设置为-1就行啦

    *****************************后续更新******************************

    Spring Boot1.4版本后配置更改为:

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

    Spring Boot2.0之后的版本配置修改为:

    spring.servlet.multipart.max-file-size = 10Mb
     
    spring.http.multipart.max-request-size=100Mb
  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    并行导致的进程数过大无法连接数据库
    Oracle 等待事件(Wait Event):Sync ASM rebalance 解析
    2套RAC环境修改scanip后客户端连接异常
    数据流通技术工具
    Hack The Box——Scavenger
    MySQL中InnoDB引擎对索引的扩展
    30分钟,教你从0到1搞定一次完整的数据可视化分析!
    【2020-MOOC-浙江大学-陈越、何钦铭-数据结构】树和堆(第五周的笔记和编程作业)
  • 原文地址:https://www.cnblogs.com/shuaiandjun/p/9643555.html
Copyright © 2011-2022 走看看