In a web application I want to store all doc, jpeg, pdf files in postgreSQL database. I know it can also be done by storing it on file system and storing its path in db, but I am not looking for that solution. I want to know following things:
Any pointers for this issue will be helpful.
Probably the best way store PDF file in postgresql is via large object. You should have a table field of type OID . The create a large object with your PDF and then store the large object OID in the table.
PostgreSQL provides two distinct ways to store binary data. Binary data can be stored in a table using the data type bytea or by using the Large Object feature which stores the binary data in a separate table in a special format and refers to that table by storing a value of type oid in your table.
PDF files are unstructured or semi-structured data, which means they don't have a fixed schema. This means that it can be challenging to store PDF file contents in a traditional SQL database. However, a NoSQL database is ideal for storing PDF file contents because it doesn't require a predefined schema.
You'll want to store the binary data as the bytea
type. Here is an example using JDBC and Postgres bytea
:
http://jdbc.postgresql.org/documentation/80/binary-data.html
This post about using bytea
and Hibernate might be of some use: proper hibernate annotation for byte[]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With