1

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

2
  • Does this answer your question? Insert an image in postgresql database Commented Jan 29, 2020 at 6:02
  • This is a duplicate question. Commented Oct 1, 2020 at 12:27

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.