How to receive a multipart POST using WEBrick, ideally streaming (not in memory)

StackOverflow https://stackoverflow.com/questions/19304494

  •  30-06-2022
  •  | 
  •  

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.

有帮助吗?

解决方案

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}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top