Javascript 如何在mean/angular js中检测从客户端下载文件是否成功
我已经创建了一个聊天应用程序,在其中我保持了通过聊天窗口发送文件的功能。现在,当客户端成功下载文件时,我想从服务器端删除这些文件。 我用的是平均堆栈Javascript 如何在mean/angular js中检测从客户端下载文件是否成功,javascript,angularjs,node.js,mongodb,express,Javascript,Angularjs,Node.js,Mongodb,Express,我已经创建了一个聊天应用程序,在其中我保持了通过聊天窗口发送文件的功能。现在,当客户端成功下载文件时,我想从服务器端删除这些文件。 我用的是平均堆栈 router.post("/postChatFileSend",ensureAuthenticatedForPost,function(req,res) { if (req.body.fileName) { var filePath = __dirname + '/../public/ChatFile/'+req.
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);
});
您可以根据自己的需要使用插件,这是一个简单的示例,您可以在客户端中使用它来管理下载的文件:
$.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');
});
这里有@TushBedva如果答案是有帮助的,请投赞成票,一点也不要,兄弟;)