如何在均值/角度js中检测是否从客户端成功下载文件 [英] how to detect whether file download successfully from client side in mean/angular js
本文介绍了如何在均值/角度js中检测是否从客户端成功下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个聊天应用程序,其中保持了通过聊天窗口发送文件的功能.现在,当客户端成功下载文件时,我想从服务器端删除文件.我正在使用MEAN堆栈.
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);
});
推荐答案
You can use jQuery File Download plugin for your purpose, it's a simple example you can use in your client for manage the downloaded file:
$.fileDownload('urlForYourFile')
.done(function () {
alert('File download a success!');
$.post('/postChatFileSend', {fileName: 'fileName'}, function(data) {
//Check the response, if the status propery is true, the file must have been removed from the server
});
})
.fail(function() {
alert('An error has ocurred');
});
这里有更多示例
这篇关于如何在均值/角度js中检测是否从客户端成功下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文