I am using Node.js and i want to store image file in Postgre database. I am using pg driver. The table in database says that data type must be "bytea". The question is: is "bytea" just "buffer" in node.js terms? If it is, is it enough to just read file with "hex" encoding? Or should i covert my file to bytea somehow?
Asked
Active
Viewed 1,001 times
0
-
Postgres is a database, not a file system...? Why not just store the image itself on disk (somewhere, lots of options on where; AWS, Azure, your own server, a NAS, etc etc) and only store the metadata in the database (e.g. the filename and location, dimensions, extension, etc)? – Mike 'Pomax' Kamermans Mar 31 '20 at 04:45
-
Storing files in the database is perfectly okay. You can find information about your current problem here, https://stackoverflow.com/a/14408194/2218253 | Also, if you need help figuring out why this is not working for you, please edit your question to show us the relevant code and the database schema for that table. – wuno Mar 31 '20 at 04:47
-
@Mike'Pomax'Kamermans well, i agree with you here, but that is other question.. – wealmostdone Mar 31 '20 at 04:48
-
@wuno thx, so i have to do it manually bu reading as hex and add "\\x", okay. I thought pg driver should do it automatically, but unfortunately not. – wealmostdone Mar 31 '20 at 04:51
-
Glad you got it figured out! I think the key in your case is making sure you are understanding the error and problem. You are trying to store the file as a binary string. So keep that in mind as you are working through this issue using that other answer. If you are not changing the file to be in the correct data type or format it will have a problem! – wuno Mar 31 '20 at 05:02