Skip to content

consider having better handling of array values #6

@foxnewsnetwork

Description

@foxnewsnetwork

Currently, array values get serialized as comma-separated strings. This is less than ideal since the only real reason to use FormData over json is to handle files, and servers have a hard time figuring out your binary from strings like "[object Object], [object Object]".

Therefore, please consider changing:
https://github.com/funtusov/ember-cli-form-data/blob/master/addon/mixins/form-data-adapter.js#L18

Ember.keys(data[root]).forEach(function(key) {
  if (typeof data[root][key] !== 'undefined') {
    formData.append(root + "[" + key + "]", data[root][key]);
  }
});

to...

Ember.keys(data[root]).forEach(function(key) {
  if (Ember.isArray(data[root][key])) {
    data[root][key].forEach(function(value) { 
      formData.append(root + "[" + key + "][]", value);
    });
  } else if (typeof data[root][key] !== 'undefined') {
    formData.append(root + "[" + key + "]", data[root][key]);
  }
});

If this is something we're interested in doing, please let me know and I will submit a PR after I fail my presentation on June 2nd

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