# FileReader upload File through Ember Data

**URL:** <https://discuss.emberjs.com/t/filereader-upload-file-through-ember-data/5531>\
**Category:** Uncategorized\
**Created:** [June 4, 2014, 6:21pm UTC](https://discuss.emberjs.com/t/filereader-upload-file-through-ember-data/5531 "2014-06-04T18:21:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![droberts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/droberts/32/15689_2.png) [@droberts](https://discuss.emberjs.com/u/droberts)\
**Post date:** [June 4, 2014, 6:21pm UTC](https://discuss.emberjs.com/t/filereader-upload-file-through-ember-data/5531/1 "2014-06-04T18:21:22Z")

</div>

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

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

```

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

```
[1] pry(#<AttachmentsController>)> @attachment.data => "\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.&nbsp; The javsacript which uploads my data is this:

```
var attachment = this.store.createRecord('attachment');
attachment.set('data', data);
attachment.save();

```

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

**readAsBinaryString** produced a different string:

```
reader.readAsBinaryString(input.files[0]);
// Note: readAsBinaryString is DEPRECATED
[1] pry(#<AttachmentsController>)> @attachment.data => "\xC3\xBF\xC3\x98\xC3\xBF\xC3\xA2\x02\x1CICC_PROFILE\x00

```

Read as text would occassionally crash when uploading a binary file

```
reader.readAsText(input.files[0]);
// crashes

```

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

```
reader.readAsDataURL(input.files[0]);
[1] pry(#<AttachmentsController>)> @attachment.data => "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. [ember.js - FileReader upload File through Ember Data - Stack Overflow](http://stackoverflow.com/questions/23898104/filereader-upload-file-through-ember-data)
