7

I was wondering how to do a real file upload (save file to server) with ember.js

Are there any good examples?

2

2 Answers 2

5

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.

2

If you read the answers in the link below, you will understand how to do file upload and save to server with emberjs:

File upload with Ember data

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()
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.