funtusov / ember-cli-form-data

Ember CLI addon that adds FormData file uploads to Ember Data
MIT License
59 stars 22 forks source link

need to update code to work with new version of ember data #9

Open koryteg opened 9 years ago

koryteg commented 9 years ago

I do not have time in the moment to look through the code and make a pr and what not. so I am just making a note here for me to come back to. when I add the mixin to my adapter it messes up the serialization of other attributes. I have user_ids that should be headed up to the server as an array of strings like so ["1", "2", "3"] but actually gets sent up as just a string like this: "1,2,3".

koryteg commented 9 years ago

this issue is actually FormData doing a join or something on the array. as you can see here https://github.com/funtusov/ember-cli-form-data/blob/master/addon/mixins/form-data-adapter.js#L35 you are just passing the value in. but FormData reformats it. I am not really sure what the work around is for this.

2 separate requests?

funtusov commented 9 years ago

Hey @koryteg thanks for filing an issue! Could you please copy the exact request that gets sent in your case and specify the version of ember-data that you're using?

koryteg commented 9 years ago

I am using ember data 1.13.8

lolmaus commented 8 years ago

I have a slug: attr('string') attribute with a value of asdf!. Here's how it looks in the payload (disableRoot: true):

------WebKitFormBoundaryIeH9hzmqnKbfDBnN
Content-Disposition: form-data; name="0"

a
------WebKitFormBoundaryIeH9hzmqnKbfDBnN
Content-Disposition: form-data; name="1"

d
------WebKitFormBoundaryIeH9hzmqnKbfDBnN
Content-Disposition: form-data; name="2"

s
------WebKitFormBoundaryIeH9hzmqnKbfDBnN
Content-Disposition: form-data; name="3"

f
------WebKitFormBoundaryIeH9hzmqnKbfDBnN
Content-Disposition: form-data; name="4"

!
------WebKitFormBoundaryIeH9hzmqnKbfDBnN--

With disableRoot: false names are slug[0], slug[1]...

lolmaus commented 8 years ago

The cause of the problem is that here:

hash.data = this._getFormData(data);

data is a hash of record attributes, while the addon seems to expect it to be a hash of hashes (unnecessary Object.keys(data[root]).forEach).

PS Ember Data 2.7.