Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在mean/angular js中检测从客户端下载文件是否成功_Javascript_Angularjs_Node.js_Mongodb_Express - Fatal编程技术网

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如果答案是有帮助的,请投赞成票,一点也不要,兄弟;)