I am currently using Net::HTTP
in a Ruby script to post files to a website via a multipart form post. It works great for small files, but I frequently have to send very large files using this script, and HTTP#post
only seems to accept post data as a String
object, which means that the file I'm sending has to be read into memory before anything can be sent. This script is running on a busy production server, so it's unacceptable to gobble up hundreds of megabytes of RAM just to send a file.
Ideally, there'd be a method that could be given a buffer size and an IO
object, and would send off buffer-sized chunks of data, reading from the IO
object only as required. What would be the best way to make this happen? Did I miss something relevant in Net::HTTP
?
Update: Net::HTTP#body_stream(input)
looks good, though the documentation is rather... sparse. Anyone able to point me to a good example of this in action?