I'm using reader.readAsArrayBuffer() to send a file to node.js so that i can save it in a /public folder.
reader.readAsArrayBuffer(event.currentTarget.files[0])
When the read is done it calls a Meteor.method()
reader.addEventListener("loadend", function(evt){
Meteor.call("saveFile", reader.result)
})
The meteor method receives a file and saves it to my public/folder.
saveFile:function(file){
var fs = Npm.require("fs")
fs.writeFile('../../../../../public/logo/jow.png', file, {encoding:"binary"}, function (err) {
console.log(err)
console.log("file saved")
});
}
However, the problem is that i never get the encoding right, and when opening the file in /public/logo/jow.png i get this message:
jow.png can not be read, it may be damaged.
But when i change readAsArrayBuffer() to readAsBinaryString() it works as expected and i can open the image.
Any ideas?