Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How: File Upload with ember.js [closed]

Tags:

ember.js

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

Are there any good examples?

like image 751
fabian Avatar asked Feb 03 '13 19:02

fabian


2 Answers

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.

like image 128
Alan Dong Avatar answered Nov 16 '22 15:11

Alan Dong


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()
like image 43
brg Avatar answered Nov 16 '22 14:11

brg