dimanche 16 août 2020

EmberJs EmberUploader uploading multiple files problem

I have an ember component uploading multiple File, this is my component:

export default EmberUploader.FileField.extend({
  multiple: true,
  method: 'POST',
  success: Ember.K,
  failure: Ember.K,
  updateLabel: Ember.K,
  start: false,
  
  change(event) {
    this.set('_files',event.target.files);
  }
  
    startUpload: Ember.observer('_files.[]', 'start', function() {
    if (!Ember.isEmpty(this.get('_files')) && this.get('start')) {
      const uploader = EmberUploader.Uploader.create({
        url: this.get('url'),
        method: this.get('method')
      });

      let args = this.get('files');

      let data = this.get('data');
      if (data) {
        args.push({data: data});
      }

      uploader.upload(this.get('_files')).then(data => {
        this.$().val('');
        this.get('success')(data);
      }, error => {
        this.$().val('');
        this.get('failure')(error);
      });
    }
  })
});

I am getting an empty file at the backend. I am cheking that '_files' is not empty. Actually console.log('this.get('files')) show a FileList. Could someone help me with this ?




Aucun commentaire:

Enregistrer un commentaire