form_data icon indicating copy to clipboard operation
form_data copied to clipboard

Robust multipart/related support?

Open paradox460 opened this issue 10 years ago • 2 comments

Duplicating the issue I opened on http (https://github.com/httprb/http.rb/issues/175), because it seems to be more relevant here:

Apologies if this already exists, but I haven't found any references to it.

Sometimes one needs to send data via multipart/related. This, so far, has been a huge pain in the ass, with almost every other ruby HTTP solution.

Comparatively, other libraries, such as Node.js' request make it downright simple. If we could get something similar to request's level of multipart/related support, it would be awesome. They not only solve the initial issue of crafting multiparts, but they go above and beyond and let you deal with some implementation caveats.

Thanks!

paradox460 avatar Jan 17 '15 04:01 paradox460

I second the request, I had to use multipart/mixed recently and had to roll my own custom solution.

Ideally it would also be possible to add custom headers (like Content-Type and Content-Disposition) to body parts.

Maybe FormData is not the right place to do this, since this isn't strictly related to 'forms' anymore. I could imagine separating Multipart handling out as a gem and having FormData at a higher abstraction level. That is, one can use FormData for the 95% of the cases where the default use case is enough, and provide a lower-level Multipart class which just deals with concatening body parts correctly etc. and let the user add custom body parts with custom headers.

I don't really know all that much about HTTP, so I don't know if this made sense. :)

Fryie avatar Apr 12 '15 23:04 Fryie

Well, initial idea of this gem was to just support emitting of multipart/form-data, but since very first release, I realized I would like it to provide a silver bullet for both emitting and parsing of request/response bodies of different types including www-urlencoded one. So I'm open for a Pull-Request (even a sketch will help a lot) as I don't have time right now to do this myself...

ixti avatar Apr 12 '15 23:04 ixti