Skip to content

adapter extracting incorrect root #17

@danjac

Description

@danjac

I'm unable to save a model due to ember-cli-form-data extracting the incorrect root.

Model:


export default Model.extend({
  title: attr(),
  image: attr('file'),
  description: attr(),
  thumbnail: attr(),
  createdAt: attr('date')
});

Controller:


import Ember from 'ember';

export default Ember.Controller.extend({
  actions: {
    submit() {

      const model = this.store.createRecord('image', {
        title: this.get('title'),
        description: this.get('description')
      });

      const image = document.getElementById('image').files[0];
      model.set('image', image);
      model.save();

    }
  }
});

This is the resulting payload:

------WebKitFormBoundarydHjcL7c0dAoCTjNp
Content-Disposition: form-data; name="title[0]"

t
------WebKitFormBoundarydHjcL7c0dAoCTjNp
Content-Disposition: form-data; name="title[1]"

e
------WebKitFormBoundarydHjcL7c0dAoCTjNp
Content-Disposition: form-data; name="title[2]"

s
------WebKitFormBoundarydHjcL7c0dAoCTjNp
Content-Disposition: form-data; name="title[3]"

t
------WebKitFormBoundarydHjcL7c0dAoCTjNp--

Working through the breakpoints I see this in the ember-cli-form-data adapter:

    _getFormData: function _getFormData(data) {
     // data is {title: 'test', description: 'test', image: File}
      var formData = new FormData();
      var root = Object.keys(data)[0]; // root is 'title'


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions