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
The 2n+1 smells like you're getting hex output from your bytea
instead of the old escaped format. I'm guessing that you're using a dedicated database and that means PostgreSQL 9.0 which has a different default encoding for bytea:
When migrating from PostgeSQL 8.x to PostgreSQL 9.x you can run into issues with binary string compatibility. The default representation is hex in version 9 but version 8 it is set to escaped. You can make PostgreSQL 9 use escaped by manually setting bytea_output.
If I'm right then you can use the instructions in the above link or use this summarized version:
DATABASE_URL
which looks like postgres://username:password@host/database_name
. heroku pg:psql
to get a PostgreSQL console.ALTER ROLE username SET bytea_output TO 'escape';
from the the psql
console where, of course, username
is the username from (1).psql
do a heroku restart
to restart your application.Then try again and hopefully you'll get the right bytes.