I am trying to generate a simple text file from a meteor collection. I would like the user to click on a button (let\'s say \'Convert to text file\' button) and he would be
If using Iron Router, add a route on the server that generates the text file and set the appropriate headers and end the response with the file generated:
Router.map(function() {
this.route('txtFile', {
where: 'server',
path: '/text',
action: function() {
var text = "This is the awesome text.";
var filename = 'textfile' + '.txt';
var headers = {
'Content-Type': 'text/plain',
'Content-Disposition': "attachment; filename=" + filename
};
this.response.writeHead(200, headers);
return this.response.end(text);
}
})
});
And on the client:
<a href="/text">Download text</a>