I am using Iron Router to create ZIP Files from Data stored in my AWS S3 Bucket. For that I would like to query my files and only put files into my ZIP Folder based on the data context in my current template.
My current Data context has two fields (_id, filetype) which are used to query my FS.Collection. Unfortunatly only the _id can be used to query my files in the router. I am not able to get filetype to iron router:
My click event:
'click #download': function() {
Router.go('zip.download', {_id: this._id, _Filetype: this.filetype});
}
My route:
/*ZIP Files*/
Router.route('/zip/:_id', {
where: 'server',
name: 'zip.download',
action: function() {
console.log(this.params); //Gives me only _id, but not _Filetype
// Create zip
var zip = new JSZip();
MyCollection.find({refrenceID: this.params._id, filetype: this.params._Filetype})
.
.
.
// End Create Zip - This part works
}
});
Whats the best way to pass data to the router?
Right now, your _Filetype
is not received because it is not declared as a valid parameter in your route: /zip/:_id
. (no mention of :_Filetype
in there)
If you don't want to put the fileType as a parameter in your route, you will still have to provide it somehow. This seems a good occasion to use query parameters!
In your click event:
'click #download': function() {
Router.go('zip.download', {_id: this._id}, , {query: 'fileType=' + this.filetype});
}
And in your route:
/*ZIP Files*/
Router.route('/zip/:_id', {
where: 'server',
name: 'zip.download',
action: function() {
console.log(this.params); //Gives me only _id, but not _Filetype
// Create zip
var zip = new JSZip();
MyCollection.find({refrenceID: this.params._id, filetype: this.params.query.fileType})
.
.
.
// End Create Zip - This part works
}
});