I want to prompt a download for a user when they click a link instead of open it in the browser.
with expressJS, it should be just like this :
app.get('/download', function (req, res) {
res.download('public/uploads/sample.pdf');
});
how can I do it with GeddyJS ?
I tried this code, but it still open it in the browser, which is mean the "resp.setHeader" is not working.
this.download = function (req, resp, params) {
var filename = 'sample.pdf';
var file = 'public/uploads/sample.pdf';
resp.setHeader('Content-Disposition', 'attachment; filename="' + filename + '"');
resp.sendFile(file);
};
Did I miss something?
Thanks a lot before.
The issue is that Geddy's response object doesn't have a 'setHeader' method, so you need to reach in and set the header on the real Node response object.
resp.resp.setHeader('Content-Disposition', 'attachment; filename="' + filename + '"');