I was wondering how to do a real file upload (save file to server) with ember.js
Are there any good examples?
I was wondering how to do a real file upload (save file to server) with ember.js
Are there any good examples?
See my answer from another thread
<input
multiple="true"
onchange={{action "upload"}}
accept="image/png,image/jpeg,application/pdf"
type="file"
/>
actions: {
upload: function(event) {
const reader = new FileReader();
const file = event.target.files[0];
let imageData;
// Note: reading file is async
reader.onload = () => {
imageData = reader.result;
this.set(data.image', imageData);
// additional logics as you wish
};
if (file) {
reader.readAsDataURL(file);
}
}
}
It just works.
If you read the answers in the link below, you will understand how to do file upload and save to server with emberjs:
In the answer provided by 'Toran Billups' in the link above, the lines below, which I copied from his answer, do the saving to server:
var person = PersonApp.Person.createRecord({username: 'heyo', attachment: fileToUpload});
self.get('controller.target').get('store').commit()