springboot 2.0 上传文件时报错,报错信息为:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (15274832) exceeds the configured maximum (10485760)] with root cause
在这里插入图片描述
原因是springboot默认的上传文件大小为1M,如果超过1M就会报此错误,修复方式为在配置文件中添加如下配置:

spring:
  servlet:
    multipart:
      # 支持的最大上传文件大小
      max-file-size: 501MB
      # 支持的最大请求大小
      max-request-size: 501MB
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐