Skip to content

Instantly share code, notes, and snippets.

@acestudiooleg
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save acestudiooleg/2459e6ccca850b3c6b2b to your computer and use it in GitHub Desktop.

Select an option

Save acestudiooleg/2459e6ccca850b3c6b2b to your computer and use it in GitHub Desktop.
How to force download file from another service without saving this file on server with NodeJS
var Request = require('request');
app.get('/forceDownloadFile', function(req, res){
Request
.get('https://goo.gl/3IYOGV') // url to another service (for example: amazon);
.on('response', function(fileRes){
res.setHeader('Content-disposition', 'attachment; filename=helloWorld.pdf');
res.setHeader('Content-type', resp.headers['content-type']);
fileRes.pipe(res);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment