ember-cli-form-data
ember-cli-form-data copied to clipboard
Not everything should be FormData
The issue is that certain fields don't need to be FormData, only the attributes with the file
transform.
I'm seeing issues with certain libraries that expect arrays to come over as arrays, and not comma separated strings. This happens with hasMany
s when you POST an attribute as an array.
Seems like there should be a type check here.
Interesting, apparently there's no sane hooks to get a model type from within the adapter, it's passed to it.
Here are two options:
- We can add an optional array of attributes that should be transformed.
- A really hacky attempt at getting this automatically, you can try if it works for you, I'll try to revisit this in case I missed something. https://gist.github.com/funtusov/743addb79699eb2f6394
I'll see what I can come up with, and give your gist a try.
I'm working on a nodejs middleware to get around this: https://github.com/knownasilya/form-data-parser
:+1: This library seems promising, but I am having trouble getting it working. I think it's because of this problem.
If I understand this correctly, I think I disagree with the premise of this issue. You can’t include FormData data in a JSON hash—JSON simply doesn’t support it. If you want to take advantage of FormData’s ability to send binary data (like for a file upload), the whole request has to be serialized as FormData, not JSON.
@knownasilya, Express’s body-parser library doesn’t handle FormData, but its README lists middleware that does:
@andrewbranch We could send JSON in a FormData field, but that doesn't seem very cool.
Sorry to resurrect this—one stop gap measure would be to only use formdata if at least one changing attribute is a file? That way, we can handle arrays in JSON format (which makes up 99% of requests) and then switch to FormData just for file uploads?
Maybe not as useful if you aren't using dirtyattribute tracking, but seems like a potential option.