I'm trying to use RestClient and Faraday to query an endpoint which returns multiple files in a multipart response. How do I parse the multipart envelopes in the response body? Rack::Utils::Multipart.parse_multipart would have done it, but in my case, this is outside of Rack. I'm open to using a different HTTP client if its helps.
Asked
Active
Viewed 1,213 times
1
-
hey did you get anywhere with this? I'm faced with the same problem. – Stewart McEwen Jul 09 '17 at 04:52
-
@Stewart Nothing yet. I just have some custom code doing it. – Akshay Rawat Jul 13 '17 at 22:38
-
@AkshayRawat did you write some code ? – Fabrizio Bertoglio Dec 17 '17 at 18:38
-
1Did you take a look at the `parse_multipart` method source? You could prob adopt it some to work for you. http://www.rubydoc.info/gems/rack/1.2.5/Rack/Utils/Multipart – mikwat Dec 18 '17 at 23:46
-
Have you checked out https://github.com/savonrb/httpi It has some mentions of multipart responses, but I didn't look closely enough to see if it handles everything. It's a wrapper around a few different http clients. – Derek Hopper Dec 22 '17 at 20:56
1 Answers
2
Almost none of the popular HTTP clients, in almost any language, handle multipart responses from a server. In fact I'd be surprised if you can easily find HTTP servers with baked in multipart response capabilities. It's just not a common use case.
You'll find the converse true though, most HTTP servers handle multipart responses built from clients.
The good news is that "multipart" is just content type like XML or JSON, so you should be able to attach any old multipart parser to the response body after you've made the request with your favorite HTTP client.
Some parsers to consider:
- https://github.com/danabr/multipart-parser
- Rack::Multipart::Parser
- Shoehorn your data into Rack::Utils.parse_multipart

fny
- 31,255
- 16
- 96
- 127