This Ember-CLI addon adds file uploads through FormData to the Ember Data
ember install ember-cli-form-data
Add a file field on the model
Add the FormDataMixin to your post adapter. Run
ember g adapter post if you don't have the adapter.
Then you can use an
<input type='file' id='file-field'/> to send the attachment:
var file = documentfiles0;model;model;
This will send the
attachment and all other attributes as a FormData object.
Flatten FormData fields
Some api's desire the form data fields to not include the root object
name. For example, the default adapter behavior would result in
in your serialized data. If your api instead expects just
disableRoot: true to remove the model name from the fields.
This addon was inspired by Matt Beedle's blog post http://blog.mattbeedle.name/posts/file-uploads-in-ember-data/