Last active
August 29, 2015 14:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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