I have a rails 3.1 app that stores images in a binary field in a postgresql database (I am aware of potential issues with storing images in a database, but have to do so for now). Everything works fine locally in development mode and specs on OSX, but all images are broken in the app deployed to Heroku. I've verified that the data in the database is correct by pointing my local machine at the same database that the heroku instance uses, and all images displayed correctly.
So, the problem seems to lie in ActiveRecord (running on Heroku) loading the data from the database. I'm also guessing it is an encoding issue. Running the rails console locally I can verify that the bytesize of these fields are correct, but running the rails console on Heroku shows an incorrect bytesize. In fact, loading an N byte file via ActiveRecord on Heroku results in a bytesize of 2N+1 for all files.
Any help is greatly appreciated.