Skip to content

Instantly share code, notes, and snippets.

@bazzel
Last active August 29, 2015 14:08
Show Gist options
  • Save bazzel/5173956dd0d4e513c4eb to your computer and use it in GitHub Desktop.
Save bazzel/5173956dd0d4e513c4eb to your computer and use it in GitHub Desktop.
<div class='form-group'>
{{#if image}}
<img {{bind-attr src=image}}/>
<button type='button' class='remove pull-right'>Remove</button>
{{else}}
<img src='http://placehold.it/320x150&text=No image'>
{{/if}}
<div class='file'>
Browse...<input type='file' accept='image/*'>
</div>
</div>
import Ember from 'ember';
export default Ember.TextField.extend({
type: 'file',
change: function (e) {
var reader = new FileReader(),
_this = this;
reader.onload = function (e) {
var fileToUpload = e.srcElement.result;
Ember.run(function() {
_this.set('file', fileToUpload);
});
};
return reader.readAsDataURL(e.target.files[0]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment