expressjs : implement http file download

Express helper, res.download

Express has a helper for this:
app.get('/xxx', function(req, res){ 
  var file = __dirname + '/xxx'; 
  res.download(file); // Set disposition and send it. 
}); 

http file download header

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
res.setHeader('Content-disposition', 'attachment; filename=xxx'); 

No comments:

Post a Comment

Building a Markdown-Based Blog System with Next.js

Building a Markdown-Based Blog System with Next.js When we decided to add a blog to https://qz-l.com/blog , we wanted something simple, fas...