为什么res.download正在下载一个空的zip文件?

时间:2016-08-03 02:14:07

标签: javascript jquery express download

我正在使用expressjs开发我的应用程序。我编写了一个服务,使用res.download(filepath, filename)在客户端下载文件。以下是我的服务。

router.route('/downloadFile').get(function(req,res){
    var filter = url.parse(req.url, true).query.filter;

    Model.find({label:filter}).exec()
    .catch(function(err){
        console.error(err);
    })
    .then(function(data){
        var fileTobeDownloadedPath = foo(); //returns a zip file path which belongs to a location in my temp folder in project

        res.download(fileTobeDownloadedPath, path.parse(fileTobeDownloadedPath).base);
    });
});

这是我的前端javascript代码

$(document).on('click','#btnDownload', function(event) {
  // I am populating the values of the array using some javascript query
  window.open('/downloadFile?filter=' + angular.element('[ng-controller=mainCtrl]').scope().mainCtrlObj.modalContent.label +
              '&tags=' + angular.element('[ng-controller=mainCtrl]').scope().mainCtrlObj.modalContent.tags.toString() +
              '&sizes=' + sizes.toString() + '&formats=' + formats.toString());
});

根据用户在前端选择的复选框,服务将调用带有zip文件路径的res.download作为参数或单个文件路径。但是,当我选择多个选项并单击下载时,我应该下载一个zip文件。

目前正在下载文件,但zip文件大小为0字节,zip文件中没有文件。

请告诉我出了什么问题。提前致谢。

0 个答案:

没有答案