FileReader: readAsArrayBuffer () vs readAsBinaryString ()

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?

+8
meteor filereader
source share

No one has answered this question yet.

See related questions:

4
Meteor: upload image file using FileReader on the client and Npm.require ("fs") on the server
2
Node.js - download and save a PDF file locally for offline files
2
Template literal captured by string variable
0
Saving an image to the file system from raw Dropbox API data using the fs.writeFile node
0
how to debug using inspector node in meteor.startup
0
Js oracle module node: console log statement does not work when select query is executed
0
YouTube API Error, Node.js
0
Undefined value when using fs.writeFile
0
Does Meteor.call fail within the stub?
0
json2csv is not a function in nodejs

All Articles