Skip to content

Instantly share code, notes, and snippets.

@badri
Created July 18, 2018 09:37
Show Gist options
  • Save badri/743bf03b74344b7cf855501d3e6a21b4 to your computer and use it in GitHub Desktop.
Save badri/743bf03b74344b7cf855501d3e6a21b4 to your computer and use it in GitHub Desktop.
/**
* GET /api/file/:id
* Download an uploaded file.
*/
export let download = (req: Request, res: Response, next: NextFunction) => {
File.findByIdAndRemove(req.params.id).exec((err, file) => {
if (err) res.status(500).send(err);
if (!file) {
res.status(404).send('not found');
return;
}
res.sendFile(path.join(__dirname, '../../uploads', file.hash));
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment