Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 382
Madhusudhan Avatar asked Sep 10 '12 20:09

Madhusudhan


1 Answers

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?

like image 93
SonOfNun Avatar answered Nov 04 '22 20:11

SonOfNun