2

NOTE


I have already gone through the below implementations and am attempting something very similar, however, I'm unable to wrap my head over how to get it to work.

  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

What I have:

An event that calles a meteor method.

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

            Router.go('/text');    
        });
    }

The meteor method that creates content for the file (File contains mongo records in json format)

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
}

A route defined in my server

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'
});

My problem

The above scenario works well when I download a file once. Subsequent clicking of the button must let me download over and over again, however, it does nothing.

I have a feeling because I'm using Router.go('/text') in my client code which is redirecting it to /text although I don't see any changes in the address bar. I can also substantiate the above since I'm able to download the file again, if I were to navigate away from the page and back to it again.

I am not sure how to fix this, can someone provide some pointers about this?

blueren
  • 2,730
  • 4
  • 30
  • 47

0 Answers0