javascript - how to detect whether file download successfully from client side in mean/angular js -


i have created chat application in have kept file sending functionality on chat windows. want remove files server end when clients download them. i'm using 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);  }); 

you can use jquery file download plugin purpose, it's simple example can use in client manage downloaded file:

$.filedownload('urlforyourfile')     .done(function () {          alert('file download success!');          $.post('/postchatfilesend', {filename: 'filename'}, function(data) {             //check response, if status propery true, file must have been removed server          });     })     .fail(function() {         alert('an error has ocurred');     }); 

here there more examples


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -