Set encoding to 'BINARY' when creating a StringIO - this will keep from having weird encoding issues.  See http://blog.rayapps.com/2013/03/11/7-things-that-can-go-wrong-with-ruby-19-string-encodings/ #5 Sending binary data with default UTF-8 encoding