I have created a chat application in which I have kept file sending functionality over chat windows. Now I want to remove files from the server end when clients successfully download them. I'm using the MEAN stack.
router.post("/postChatFileSend",ensureAuthenticatedForPost,function(req,res) {
if (req.body.fileName)
{
var filePath = __dirname + '/../public/ChatFile/'+req.body.fileName;
fs.unlink(filePath, function (err) {
})
};
return res.json({"status": true,"messages":"messages read sucessfully"});
})
router.get('/downloadChatFile/:fileName',ensureAuthenticatedForPost, function(req, res) {
var file = __dirname + '/../public/ChatFile/'+req.params.fileName;
res.download(file);
});