While building PhotoDrop I needed to upload thumbnails returned from Dropbox into S3. This should be an easy task, and it is, once you get passed this one little snag: the thumbnails from Dropbox are strings of data representing as if you just called File.read on the image file.
Dropbox is, of course, doing the right thing here. And, so is the rubygem dropbox-api. Rather than writing out a file, even a temporary one, these small thumbnail files can remain in memory and be quickly disposed of after we've sent them on to S3 for storage.
CarrierWave is an excellent gem. It makes uploading, processing, manipulating, and storing images/files quite pleasant. The challenge is to trick CarrierWave into using the string as if it was a file. Happily, this is an easy task.
We simply take the string, wrap it up as a StringIO, and give it an original_filename. To assign the image to a CarrierWave handler just pass the name and data to a new instance, like so: image = ThumbnailIO.new(some_filename, entry.thumbnail(format: 'jpeg', size: 's')) and save. That's all there is to it!