Download function helps download a file at a particular path.

PHOTO EMBED

Tue Mar 30 2021 06:01:42 GMT+0000 (Coordinated Universal Time)

Saved by @shubham75089 #javascript #node.js #express

const fs = require('fs')

exports.download = (req, res, next) => {
  console.log('fileController.download: started')
  const path = req.body.path
  const file = fs.createReadStream(path)
  const filename = (new Date()).toISOString()
  res.setHeader('Content-Disposition', 'attachment: filename="' + filename + '"')
  file.pipe(res)
}
content_copyCOPY