0

Given a JSON file of data to be inserted into a table in Postgresql. One of the fields in the JSON structure is a base64 string. I know there is a data type for psql called BYTEA but how would one insert the base64 string in that field.

I also need to then be able to select the base64 string from the table and display the image in the end.

Note: Bonus points for Golang solutions cause the whole app is in Golang

adarian
  • 334
  • 7
  • 24
  • 1
    https://stackoverflow.com/questions/55170508/postgresql-how-to-insert-base64-images-strings-into-a-bytea-column – Manvir Dec 30 '20 at 03:58
  • @Tyger ty for the insert link, but would I just do an `encode()` ... or is that not a thing. Also, can this be done on the Golang side or does this have to be a psql query? – adarian Dec 30 '20 at 04:17
  • you can create a custom type and encode decode in parsing phase – Shubham Srivastava Dec 30 '20 at 04:28
  • 1
    Just decode to []byte in Go and insert that directly in the database. The JSON decoder will base64-decode automatically. – Peter Dec 30 '20 at 08:45

0 Answers0