How to use Url as parameter res.download() from expressjs

Issue

I found a example from expressjs:
res.download(‘/report-12345.pdf’);
to prompt the user for download. But i pass a url as parameter. It not working.

Solution

res.download just accepts path to filesystem in local.

For your requirement you can do one of below:

1) use res.redirect({URL})

2) get that file from URL and then send file to client like :

app.get('/', function(req, res){  
http.get(URL, function(file) {
  file.pipe(res);
});
});

Answered By – Ebrahim Pasbani

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published