Question

I wish to receive a multipart POST of large files. I have not been able to find any real support for this using WEBrick. All I have found is if you use request.query(), you get a HASH of the data indexed using the names from the headers. However, ruby hashes are not ordered, so this does not allow you to reconstruct the data correctly. Also, it would be nice to stream the data to a file, instead of loading it entirely in memory.

Was it helpful?

Solution

So I figured it out except for the streaming. As long all the headers for the multipart chunks have the same name (Content-Disposition: form-data; name=\"some_name\"), all the data will be grouped together in a WEBrick::HTTPUtils::FormData object, accessed using:

request.query['some_name']

and each data element can be iterated over in order using:

request.query['some_name'].each_data {|data| puts data.to_s}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top