简体   繁体   English

如何使用nodejs实现分段文件上传代理?

[英]How to implement multipart file upload proxy using nodejs?

We have implemented a proxy server for our main backend server which actually serve all requests using express-http-proxy npm package.我们已经为我们的主要后端服务器实现了一个代理服务器,它实际上使用 express-http-proxy npm 包为所有请求提供服务。 This works fine for all request except multipart request, as multipart is not working with this.这适用于除 multipart 请求之外的所有请求,因为 multipart 不适用于此。 When i upload a small size file, it works fine as in that case body is redirected to main server once read completely.当我上传一个小文件时,它工作正常,因为在这种情况下,一旦完全读取,主体就会重定向到主服务器。

In case on multipart request it fails and nothing reaches backend server (as it is trying to load complete body before proxying).如果在多部分请求中它失败并且没有任何东西到达后端服务器(因为它试图在代理之前加载完整的主体)。 On exploration found this https://github.com/villadora/express-http-proxy/issues/127 which clearly says it is not supported.在探索中发现这个https://github.com/villadora/express-http-proxy/issues/127明确表示它不受支持。

On further exploration found multer nodejs library which helps support save multipart file, but not sure how to use it for proxying multipart file request to backend server.进一步探索发现 multer nodejs 库,它有助于支持保存多部分文件,但不确定如何使用它来代理对后端服务器的多部分文件请求。

Please give some direction of how to proceed on implementing "multipart file upload proxy" using nodejs.请给出如何使用 nodejs 继续实现“多部分文件上传代理”的一些指导。

One of the best solutions for nodeJS is needle https://github.com/tomas/needle#request-options nodeJS的最佳解决方案之一是needle https://github.com/tomas/needle#request-options

and they do support File upload using multipart, passing file path 并且它们确实支持使用分段传递文件路径的文件上传

check solution bellow, works with array of files.检查下面的解决方案,适用于文件数组。

How to proxy file upload from express to remote? 如何代理文件从快递上传到远程?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM