Passing binary file data through and saving to filesystem

Skip to first unread message

Joshua Ellis

Mar 5, 2015, 7:19:25 PM3/5/15
Man, this is driving me crazy. I'm trying to use the HTML5 FileReader API to allow uploads of MP3s to a server -- I can't store them as GridFS as I'm doing some other stuff to them via command line, etc. I'm using the reader.readAsText() function of the FileReader API, which encodes the uploaded data as UTF-8 by default, wthen doing a to pass the file (as a string) to the server, which then reads the string, creates a Buffer, and writes a file, like so:

Client side:

// this is triggered by a change event

= $(e.currentTarget)[0].files[0];
var reader = new FileReader();

.onload = function(e){'processMedia',, function (error, result) {
if(err) throw err;


Server side:

fs = Npm.require('fs');


'processMedia' : function(data){

= new Buffer(data, 'utf-8');
= "/tmp/" + new Date().getTime() + '.mp3';
.writeFile(filename, buffer, function (err) {
if (err) throw err;
return "It's saved!";


So here's the maddening part: it works, the file is saved. When I open it, the MP3 player reads the metadata correctly, but the file won't play. So I tried doing JPGs instead of MP3s, to see what that did, and they're also broken.

I know I can't send an ArrayBuffer through, so my options seem to be text or binary string (which I don't want to do, as it's deprecated).

So what am I missing here? It's driving me nuts. :-) Anybody got any ideas?

Avital Oliver

Mar 5, 2015, 7:41:42 PM3/5/15
We're moving the forums to, so it's better to ask there. (This group will be closed in a few days)

You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit

Reply all
Reply to author
0 new messages