node.js - 流文件暂时不保存 [英] node.js - stream file without saving it temporarily
问题描述
什么是最简单和最好的方法来实现呢?
我可以将文件上传到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屋!