How: Download a file using ember.js

I was wondering how to make a real file upload (save the file to the server) using ember.js

Are there any good examples?

+5
source share
4 answers

If you read the answers in the link below, you will understand how to download and save files on the server using emberjs:

Download Ember Data File

In the answer provided by "Toran Billups" in the link above, the lines below, which I copied from his answer, save to the server:

var person = PersonApp.Person.createRecord({username: 'heyo', attachment: fileToUpload});

self.get('controller.target').get('store').commit()
+2
source

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
source
+1

, Ember NYC May 2015 meetup.

https://github.com/tim-evans/ember-nyc-may-2015

Youtube video: https://youtu.be/sZs-VXWIDh0

Hope this helps too.

0
source

All Articles