node.js - 流文件暂时不保存 [英] node.js - stream file without saving it temporarily

查看:131
本文介绍了node.js - 流文件暂时不保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我的设置我有一个客户端从哪个文件上传到node.js服务器(serverA),从那里我想流文件到另一台服务器(serverB)没有临时保存文件(在serverA上)。

什么是最简单和最好的方法来实现呢?



我可以将文件上传到serverA,但我不希望临时文件被存储。



<更新:

它的一个简单的ajax文件上传到(severA)...这个想法是传输字节,所以即使如果连接断开,您可以从该特定字节读回。



我在serverA上使用express.js,而backbone.js是我使用的客户端ajax上传。现在A和B之间没有连接,它们通过端点进行通信。 serverA在端口4000上运行,serverB在端口5000上运行。我想以某种方式将文件从serverA传送到serverB上的端点。由于HttpRequest是一个流,你可以使用 request 模块将你当前的请求传送到你快速路由中的另一个端点:$ b​​
$ b $ $ $ $ $ $ $ app.post('myroute',function(req, res){
var request = require('request');
req.pipe(request.post('/ my / path:5000'))。pipe(res);
} );

这个方法可行吗?

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).

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.

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.

I am using express.js on serverA and backbone.js is the client using which I do the ajax uploads. For now there's no connection between A and B as such, they communicate through endpoints. 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.

解决方案

Since HttpRequest is a stream, you could use the request module to pipe the current request into the other endpoint inside your express route:

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

Would that approach work?

这篇关于node.js - 流文件暂时不保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆