Richard Crowley’s blog

MultIO Ruby IO multiplexer

All across the Internet, Rubyists load entire files into memory to create multipart HTTP POST requests, seemingly unaware of Net::HTTP’s ability to stream an IO-like object using Net::HTTPGenericRequest#body_stream=.  All it needs is an object that implements read(length).  So, here we go, a multipart HTTP POST without loading the entire file into memory at once.

The MultIO class is an Array but you should use MultIO#<< to append new Strings, Files or other IO-like objects.  In order to use MultIO with Net::HTTP, all objects appended need to be able to find their size so the Content-Length header can be set.

The whole shebang: http://gist.github.com/493562.