【问题标题】:Spring Cloud Netflix Zuul large file uploadSpring Cloud Netflix Zuul 大文件上传
【发布时间】:2018-08-25 07:35:31
【问题描述】:

我正在为一个项目使用 Spring Boot,我正在尝试上传大文件,但不知何故它不起作用。

我有 Spring Boot + Zuul (@EnableZuulProxy) 在端口 8080 上运行,然后是另一个应该处理上传的微服务(我们称之为数据存储)。

我向http://localhost:8080/zuul/my/upload/endpoint 发布了一个多部分请求,其中包含一个文件和一个文本字符串。

当我上传 100MB 的文件时,一切正常。 Zuul 将请求传递给数据存储,请求进来并被存储。 但是,当我尝试上传更大的文件(150MB)时,Zuul 处理请求并将其传递给数据存储,但随后某处的多部分参数之一从请求中被剥离,然后数据存储错误返回 400 并显示“必需的请求部分”字符串'不存在'。

我在微服务(zuul 和数据存储)中都有以下配置

spring:
  servlet:
    multipart:
      max-file-size: 1000MB
      max-request-size: 1000MB

有人知道如何解决这个问题吗?我已尝试添加 CommonsMultipartResolver,但这并没有改变任何东西。

【问题讨论】:

  • 您使用的是哪个版本的 Spring-boot?

标签: spring-boot spring-cloud netflix-zuul


【解决方案1】:

您应该使用 http,而不是 servlet。

在我的 Zuul application.yml 中,以下属性有效:

spring:
  http:  
    multipart:
      max-file-size: 1000MB
      max-request-size: 1000MB

在 Spring boot 2 中,以下属性起作用:

spring:
  servlet:
    multipart:
      max-file-size: 1000MB
      max-request-size: 1000MB

这里解释了属性:

{
   "name": "spring.http.multipart.max-file-size",
   "type": "java.lang.String",
   "description": "Max file size. Values can use the suffixes \"MB\" or \"KB\" to indicate megabytes or\n kilobytes respectively.",
   "sourceType": 
   "org.springframework.boot.autoconfigure.web.MultipartProperties",
   "defaultValue": "1MB"
},
{
   "name": "spring.http.multipart.max-request-size",
   "type": "java.lang.String",
   "description": "Max request size. Values can use the suffixes \"MB\" or \"KB\" to indicate megabytes or\n kilobytes respectively.",
   "sourceType": 
   "org.springframework.boot.autoconfigure.web.MultipartProperties",
   "defaultValue": "10MB"
},

【讨论】:

  • 这个答案可能会受益于一些更多的解释和可能的一些重新格式化。
  • 从 Spring-Boot 2.0 spring.http 更改为 spring.servlet。
  • 是的,我刚刚添加了我的答案;)
猜你喜欢
  • 2020-04-15
  • 2016-09-30
  • 1970-01-01
  • 1970-01-01
  • 2021-09-07
  • 2020-07-19
  • 1970-01-01
  • 1970-01-01
  • 2020-01-02
相关资源
最近更新 更多