for my application I need to store images with their SHA-256 hash values in the database as bytea columns.
For example:
Image: http://i.imgur.com/Yt7JuZA.jpg
SHA-256: 98A5EC4F6409B5BAB4DD7F0F13AA3E8404B48B09C6B41FEA6C2EDC331DF8293C
My images table looks like this:
Code: Select all
create table images
(
image_id serial,
image bytea,
hash bytea,
primary key (image_id)
);
I use a WinForms application with PictureEdit (DevExpress) and PgSqlDataTable to let the user choose the image and then save it to the database.
The images get saved in the database and I can view and export them.
However the inserted binary value is different from the original file and therefore I get an incorrect hash.
I noticed that when I use this function to import the image with pgAdmin in the database it works fine: http://dba.stackexchange.com/a/2962/105745
However this function relies on a local file on the database server. By using the PictureEdit and PgSqlDataTable I can choose local files - which is important.
I compare the inserted bytea binary string in the database:
pgAdmin:
Code: Select all
\377\330\377\340\000\020JFIF\000\001\001\002\000\034\000\034\000\000\377\333\000C\000\003\002\002\002\002\002\003\002\002\002\003\003\003\ (...)
Code: Select all
\377\330\377\340\000\020JFIF\000\001\001\001\000G\000G\000\000\377\333\000C\000\003\002\002\002\002\002\003\002\002\002\003\003\003\003\004\ (...)
My guess is that the image header somehow gets corrupted.
Why is this change happening and how can I stop it?