Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 9
    What if the data was coming in from a HTTP request instead of a file and we had to let users download the file in a streaming way? Commented Sep 20, 2017 at 15:37
  • 3
    @summerNight - well, that is a different case than the question specified. search for nodejs proxy file download response for best practice Commented Sep 20, 2017 at 17:13
  • @1UC1F3R616 I ended up solving the problem like this: router.get(API_PREFIX + '/file-download', function (req, res, next) { var file = process.env.FILE_DOWNLOAD_LOCATION + '/' + req.query.filename res.download(file); }); Commented Jul 24, 2020 at 16:24
  • 1
    @summerNight and @1UC1F3R616 note that you are vulnerable to directory traversal attacks. for instance https://.../api?filename=../../../keys/my-secret-ssl-key.pem. to avoid that, you need to validate the query param Commented Jul 25, 2020 at 13:36