I am wondering how to insert an image into a postgres database in column of type bytea, do I have to insert from the path of the PGDATA? Thanks
1 Answer
One way of doing this is creating a column with bytea datatype and run this query:
insert into table(bytea column) values( bytea('C:\image.jpg'));
This will convert store "C:\image.jpg" into the binary representation, and later image can be retrieved from the folder.
Another efficient way of doing this is to convert the image to base64 string and store that in the database.