Created
July 18, 2018 09:37
-
-
Save badri/743bf03b74344b7cf855501d3e6a21b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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