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