vendredi 14 août 2020

Spring boot backend receiving empty Files array from EmberJs component EmberUploader When upload multiple files

I have an ember component responsible of 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);
      });
    }
  })
});

This is my spring boot controller :

public List<FileData> upload(@RequestPart("data") MemberData memberData, @RequestParam("files") MultipartFile[] uploadedFiles) throws SizeLimitExceededException {
    ...
}

My problem is that I am getting an empty array of uploadedFiles. This works fine with on file, when using MultipartFile instead of MultipartFile[] and putting this.get('files')[0] withing args.

Why this is not working for multiple files? Could someone help with this ?




Aucun commentaire:

Enregistrer un commentaire