Iron路由器提供文件下载

时间:2017-07-05 13:29:29

标签: javascript node.js meteor iron-router meteor-blaze

我已经完成了以下的实现,并尝试了非常类似的东西,但是,我无法解决如何使其工作的问题。

  1. How to serve a file using iron router or meteor itself?
  2. How to serve static content (images, fonts etc.) using iron router
  3. Meteor, generate and download file
  4. 我有什么:

    对流星方法进行调用的事件。

    'click #export'(event){
            event.preventDefault();
           Meteor.call('getExportBundleFile',AutoForm.getFieldValue('selectFlowTemplates','flowTemplateSelector'),function(error,resp){
    
                Router.go('/text');    
            });
        }
    

    为文件创建内容的meteor方法(File包含json格式的mongo记录)

    getExportBundleFile: function(flowTemplateNames){
    
            var username = Meteor.user().username;
            var filename = username + "_" + moment(new Date()).format("YYYY-MM-DD-HHMMss")+".ez";
             actualFlowTemplateContent = [];
            flowTemplateNames.forEach(function(flowTemplate){
                actualFlowTemplateContent.push(templates.findOne({flowTemplateName: flowTemplate}));
            });
    
    
             headers = {
                'Content-Type': 'text/plain',
                'Content-Disposition': "attachment; filename=" + filename
            };
    
            return filename
    }
    

    我服务器中定义的路线

    Router.route('/text', function() {
        // NodeJS request object
        var request = this.request;
        // NodeJS  response object
        var response = this.response;
    
        this.response.writeHead(200, headers);
        this.response.end(actualFlowTemplateContent);
    }, {
        where: 'server'
    });
    

    我的问题

    当我下载文件一次时,上述情况很有效。随后点击按钮必须让我一遍又一遍地下载,但是,它什么都不做。

    我有一种感觉,因为我在我的客户端代码中使用Router.go('/text')并将其重定向到/text,尽管我没有看到地址栏中的任何更改。 我也可以证实上述内容,因为我可以再次下载文件,如果我要离开页面再返回它。

    我不知道如何解决这个问题,有人可以提供一些指示吗?

0 个答案:

没有答案
相关问题