简体   繁体   English

node.js-流文件而无需临时保存

[英]node.js - stream file without saving it temporarily

So this is my setup 这是我的设置

I have a client from which files are uploaded to the node.js server (serverA) and from there I want to stream the files to another server (serverB) without saving the file temporarily (on serverA). 我有一个从中将文件上传到node.js服务器(serverA)的客户端,并且我希望从那里将文件流传输到另一台服务器(serverB), 而又不临时保存文件(在serverA上)。

What is the simplest and the best way to achieve this? 实现此目的的最简单和最佳方法是什么?

I am able to upload the file to serverA but I don't want the temporary file to be stored. 我可以将文件上传到serverA,但是我不想存储临时文件。

Update: 更新:

its a simple ajax file uplaod to (severA)... The idea is to transfer byte-wise so that even if the connection goes off, you can read it back from that particular byte. 其简单的ajax文件可升级为(severA)...这个想法是按字节传输的,这样即使连接断开,您也可以从该特定字节读回它。

I am using express.js on serverA and backbone.js is the client using which I do the ajax uploads. 我在serverA上使用express.js,而骨干.js是我执行ajax上传的客户端。 For now there's no connection between A and B as such, they communicate through endpoints. 目前,A和B之间没有连接,它们通过端点进行通信。 serverA is running on port 4000 and serverB on port 5000. I want to somehow pipe the file from serverA to an endpoint on serverB. serverA在端口4000上运行,serverB在端口5000上运行。我想以某种方式将文件从serverA传输到serverB上的端点。

Since HttpRequest is a stream, you could use the request module to pipe the current request into the other endpoint inside your express route: 由于HttpRequest是流,因此您可以使用request模块将当前请求通过管道传递到快速路由内的另一个端点:

app.post('myroute', function (req, res) {
    var request = require('request');
    req.pipe(request.post('/my/path:5000')).pipe(res);
});

Would that approach work? 这种方法行得通吗?

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

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