Wednesday, 15 September 2010

node.js - fileReader: readAsArrayBuffer() vs readAsBinaryString() -



node.js - fileReader: readAsArrayBuffer() vs readAsBinaryString() -

i'm using reader.readasarraybuffer() send file node.js can save in /public folder.

reader.readasarraybuffer(event.currenttarget.files[0])

when read done calls meteor.method()

reader.addeventlistener("loadend", function(evt){ meteor.call("savefile", reader.result) })

the meteor method receives file , saves 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, problem never encoding right, , when opening file in /public/logo/jow.png message:

jow.png can not read, may damaged.

but when alter readasarraybuffer() readasbinarystring() works expected , can open image.

any ideas?

node.js meteor filereader

No comments:

Post a Comment