I want to stream content to clients which is possibly stored in db, which they would save as files.
Obviously res.download would do the job nicely, but none of the r
You can stream directly to the response object (it is a Stream).
A basic file stream would look something like this.
function(req, res, next) {
if(req.url==="somethingorAnother") {
res.setHeader("content-type", "some/type");
fs.createReadStream("./toSomeFile").pipe(res);
} else {
next(); // not our concern, pass along to next middleware function
}
}
This will take care of binding to data
and end
events.
Make sure that your AJAX request from the client has an appropriate 'responseType' set. for example like
$http({
method :'GET',
url : http://url,
params:{},
responseType: 'arraybuffer'
}).success()