ember-cli-form-data icon indicating copy to clipboard operation
ember-cli-form-data copied to clipboard

Not everything should be FormData

Open knownasilya opened this issue 9 years ago • 7 comments

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 hasManys when you POST an attribute as an array.

Seems like there should be a type check here.

knownasilya avatar Feb 16 '15 23:02 knownasilya

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:

  1. We can add an optional array of attributes that should be transformed.
  2. 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

funtusov avatar Feb 17 '15 01:02 funtusov

I'll see what I can come up with, and give your gist a try.

knownasilya avatar Feb 19 '15 13:02 knownasilya

I'm working on a nodejs middleware to get around this: https://github.com/knownasilya/form-data-parser

knownasilya avatar Feb 20 '15 14:02 knownasilya

:+1: This library seems promising, but I am having trouble getting it working. I think it's because of this problem.

rchrd2 avatar Feb 21 '15 06:02 rchrd2

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 avatar Apr 11 '15 18:04 andrewbranch

@andrewbranch We could send JSON in a FormData field, but that doesn't seem very cool.

miguelcobain avatar Jul 24 '15 00:07 miguelcobain

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.

nybblr avatar Jan 19 '16 20:01 nybblr