Template.pixUpload.events({
'change .myPixInput': function(event, template) {
event.preventDefault();
var file = event.target.files[0]; //assuming you have only 1 file
var reader = new FileReader(); //create a reader according to HTML5 File API
reader.onload = function(event){
var result = reader.result //assign the result, if you console.log(result), you get {}
var buffer = new Uint8Array(result) // convert to binary
MyPix.insert({binary: buffer});
}
reader.readAsArrayBuffer(file); //read the file as arraybuffer
//reader.readAsDataURL(file)
}
})
As of Meteor 1.0, when you send binary/buffer inside Meteor.call or collection.insert, it get converted to EJSON from the client, then when it reaches the server, it get converted back to the original binary/buffer
If you open the chrome console and look at the websocket traffic, you see the EJSON binary string, which is base64 encoded. So the alternative way is to use reader.readAsDataURL, this converts your image directly to base64, saving Meteor from doing this again.
reader.onload = function(event){
MyPix.insert({binary: reader.result});
}
reader.readAsDataURL(file);