Created
September 3, 2018 13:35
-
-
Save bastientanesie/e4ccdeab19f9cf57967d6377b1dffe65 to your computer and use it in GitHub Desktop.
ember-pouch attachment bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import EmberObject from '@ember/object'; | |
export default Controller.extend({ | |
actions: { | |
// action bound to a test button | |
test() { | |
let avatarDOMElement = document.getElementById('user-avatar-input'); | |
if (avatarDOMElement.files.length > 0) { | |
let file = avatarDOMElement.files[0]; | |
let newAvatar = new EmberObject({ | |
name: file.name, | |
content_type: file.type, | |
data: file | |
}); | |
this.get('model').get('avatar').addObject(newAvatar); | |
this.get('model').save(); | |
} | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /models/user.js | |
import DS from 'ember-data'; | |
import Model from 'ember-pouch/model'; | |
export default Model.extend(Validations, { | |
email: DS.attr('string'), | |
username: DS.attr('string'), | |
avatar: DS.attr('attachment', { | |
defaultValue: function() { | |
return []; | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment