通过Zuul上传大文件

编程入门 行业动态 更新时间:2024-10-22 18:32:55
本文介绍了通过Zuul上传大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在通过zuul上传大文件时遇到了问题. 我正在使用apache-commons文件上传( commons.apache/proper/commons-fileupload/)来传输大文件,以及我在前面使用zuul. 在我的Spring Boot应用程序中,我禁用了Spring提供的上传功能,以使用apache commons中的上传功能:

I've faced a problem uploading big files through zuul. I'm using apache-commons file upload(commons.apache/proper/commons-fileupload/) to stream large files as well as I use zuul on the front. In my Spring Boot application I have disabled upload provided by Spring to use the one from apache commons:

spring: http: multipart: enabled: false

控制器看起来像这样:

public ResponseEntity insertFile(@PathVariable Long profileId, HttpServletRequest request) throws Exception { ServletFileUpload upload = new ServletFileUpload(); FileItemIterator uploadItemIterator = upload.getItemIterator(request); if (!uploadItemIterator.hasNext()) { throw new FileUploadException("FileItemIterator was empty"); } while (uploadItemIterator.hasNext()) { FileItemStream fileItemStream = uploadItemIterator.next(); if (fileItemStream.isFormField()) { continue; } //do stuff } return new ResponseEntity(HttpStatus.OK); }

如果我直接访问我的应用程序(不使用zuul),则文件上传将按预期进行.但是,如果通过zuul访问,则FileItemIterator没有要遍历的项目,并且请求立即完成并显示错误(ERR_CONNECTION_RESET).对于zuul,我还禁用了Spring提供的multipart.否则,它将起作用.但是,不会流式传输文件.只有在我进入控制器内部后,它们才会完全加载(常规的Spring行为).有没有办法在zuul中使用apache-commons流选项?

If I access my application directly(without zuul), file upload works as intended. However, if it's accessed through zuul, FileItemIterator doesn't have items to traverse and request finishes with error immediately(ERR_CONNECTION_RESET). For zuul I have also disabled multipart given by Spring. Otherwise, it works. However, the files are not streamed. They are loaded completely and only after I get inside the controller(regular Spring behavior). Is there a way to use apache-commons streaming options with zuul?

推荐答案

我找到了一个解决方案. 基本上在这里描述:

I've found a solution. It's basically described here:

cloud.spring.io/spring- cloud-static/spring-cloud.html#_uploading_files_through_zuul

我做了什么使它起作用.只需一步一步即可:

What I did to make it work. Just step by step:

  • 要绕过Spring DispatcherServlet,我更改了URL:
  • 发件人: localhost:8081/MyService/file

    收件人: localhost:8081/zuul/MyService/file

  • 保留对Spring分段上传的禁用:

  • Preserved disabling of Spring multipart upload: spring: http: multipart: enabled: false

  • 以下标头不是必需的. 传输编码:分块

    The following header is not required. Transfer-Encoding: chunked

    我尝试上传一个没有大文件的文件,这很好.

    I tried to upload a large file without that one and it was fine.

    更多推荐

    通过Zuul上传大文件

    本文发布于:2023-11-25 17:40:26,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1630715.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:大文件   上传   Zuul

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!