Images storing techniques

Started by Riccardo Gobboalmost 3 years ago4 messages
#1Riccardo Gobbo
riccardo.gobbo.2@studenti.unipd.it

Good evening,
I'm a Master degree student at University of Padua in Italy and I'm
developing a web application as assignment for the Web application course.

Context: the Web application that my group is developing would ideally be
used to manage county side fairs where there would be foods and drinks,
these displayed into a digital menu.
The application uses postgre to implement a database where stores data,
mostly strings as emails and orders but also some images (representing the
dishes).
The web pages are created using java servlets and jbc

Question: for better performance is it better to store images as BYTEA or
convert every image in base64 and store the generated string (so in html
it's enough to insert the base64 string in the tag)?
Converting an image in base64 would use a 30% more memory than storing
directly the image's bytes, but I don't know if working with characters
rather than bytes could have more prons than cons

Thank for the time you dedicated for the answer and I apologize both for
disturbing you and my English.

Best regards, Riccardo.

Computer Engineering
Mat. 2082156

#2Gaetano Mendola
mendola@gmail.com
In reply to: Riccardo Gobbo (#1)
Re: Images storing techniques

I would suggest to store your images in a file system and the store paths
to those images.

You can keep files and entries in your database synced via triggers/stored
procedures (eventually written in python since pgsql doesn't allow you to
interact with the file system).

On Thu, Mar 30, 2023, 11:22 Riccardo Gobbo <
riccardo.gobbo.2@studenti.unipd.it> wrote:

Show quoted text

Good evening,
I'm a Master degree student at University of Padua in Italy and I'm
developing a web application as assignment for the Web application course.

Context: the Web application that my group is developing would ideally be
used to manage county side fairs where there would be foods and drinks,
these displayed into a digital menu.
The application uses postgre to implement a database where stores data,
mostly strings as emails and orders but also some images (representing the
dishes).
The web pages are created using java servlets and jbc

Question: for better performance is it better to store images as BYTEA or
convert every image in base64 and store the generated string (so in html
it's enough to insert the base64 string in the tag)?
Converting an image in base64 would use a 30% more memory than storing
directly the image's bytes, but I don't know if working with characters
rather than bytes could have more prons than cons

Thank for the time you dedicated for the answer and I apologize both for
disturbing you and my English.

Best regards, Riccardo.

Computer Engineering
Mat. 2082156

#3Peter Eisentraut
peter.eisentraut@enterprisedb.com
In reply to: Riccardo Gobbo (#1)
Re: Images storing techniques

On 29.03.23 23:29, Riccardo Gobbo wrote:

Question: for better performance is it better to store images as BYTEA
or convert every image in base64 and store the generated string  (so in
html it's enough to insert the base64 string in the tag)?
Converting an image in base64 would use a 30% more memory than storing
directly the image's bytes, but I don't know if working with characters
rather than bytes could have more prons than cons

Storing as bytea is better.

#4Bruce Momjian
bruce@momjian.us
In reply to: Gaetano Mendola (#2)
Re: Images storing techniques

On Thu, Mar 30, 2023 at 11:30:37AM +0200, Gaetano Mendola wrote:

I would suggest to store your images in a file system and the store paths to
those images.

You can keep files and entries in your database synced via triggers/stored
procedures (eventually written in python since pgsql doesn't allow you to
interact with the file system). 

You might want to read this blog entry:

https://momjian.us/main/blogs/pgblog/2017.html#November_6_2017

--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com

Embrace your flaws. They make you human, rather than perfect,
which you will never be.