I'm trying to upload and read a file on the fly in meteor. However I didn't find any packages/tutorials to do this so I tried to use the FS library but I have some troubles with it.
I have a in my template, and an event like this :
"change .myFileUpload": function(e, tmpl) {
e.preventDefault();
var fileInput = tmpl.find('input[type=file]');
console.log('test');
// grab a list of the files selected with the file chooser
// input
debugger;
console.log(fileInput);
var theFile = new FS.File(fileInput);
console.log(theFile);
var rose = JSON.parse(Assets.getText(fileInput));
Meteor.call('readTxtFile',fileInput);
Meteor.call('readTxtFile',theFile);
}
The method readTxtFile looks like this :
readTxtFile : function(file){
console.log(file);
fs.readFile(file, function(err,data){
if(err){
throw new Error("Fail read");
}else{
console.log(data);
}
});
But, when I upload a file, the page is reloaded with the file passed through arguments, the url looks like this : http://localhost:3000/port?myFileUpload=textfile.txt
The page is reloaded when the code execute the line http://localhost:3000/port?myFileUpload=textfile.txt
Even if I set a FS.debug = true; I can't see any error, neither through the client nor the server log; except the first log
console.log(fileInput);
> <input type="file" class="myFileUpload"> portTmpl.js:12
Any thoughts ?