I am using reader.readAsArrayBuffer () to send the 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 Meteor.method ()
reader.addEventListener("loadend", function(evt){ Meteor.call("saveFile", reader.result) })
The meteor method receives the file and saves it in 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 I open 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?
kevinius
source share