FileReader upload File through Ember Data


I have an old Rails form that I want to translate into Ember Data:

  <input type="file" name="myfile" />
  <input type="submit" />

What gets stored in the database needs to match what I currently do.  Users can upload files of all types, not just binary.  I choose a particular image, and in the database, the file data begins with this:

[1] pry(#<AttachmentsController>)> => "\xC3\xBF\xC3\x98\xC3\xBF\xC3\xA2\x02\x1CICC_PROFILE\x00

I want to convert the form to upload using javascript and Ember.JS Data, not form submission.  The javsacript which uploads my data is this:

var attachment ='attachment');
attachment.set('data', data);;

The problem is data.  When it gets to the server, it’s different than how it was for the form.  I’ve tried reading the data in multiple ways:

readAsBinaryString produced a different string:

// Note: readAsBinaryString is DEPRECATED
[1] pry(#<AttachmentsController>)> => "\xC3\xBF\xC3\x98\xC3\xBF\xC3\xA2\x02\x1CICC_PROFILE\x00

Read as text would occassionally crash when uploading a binary file

// crashes

readAsDataURL produced results that didn’t match what I need to store in my database

[1] pry(#<AttachmentsController>)> => "data:image/jpeg;base64,/9j/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtb

readAsArrayBuffer looks promising, but I’m not sure what I should do with the arrayBuffer to send

Any help is appreciated!

Note: This is a crosspost of what’s on StackOverflow. I received no responses there after 8 days.