jsppostgresqljakarta-eearrays

Displaying binary images on JSP page


I have images stored in PostgreSQL in bytea (byte array) type. Also, I have a home JSP page, which has to display all photos from db. Please, point me to the solution or some ways to achieve this requirement.


Solution

  • Use [img src="url"] tag to reference your images from the database and show on the site.

    var blob = new Blob([bytes], {type: "image/jpg"});
    var url = URL.createObjectURL(blob, { oneTimeOnly: true });
    

    Blob is actually supported directly by URL.createObjectURL. The only catch is that you have to specify a mime format to identify the buffer format, which in my case is possible.

    So after you get the url use the image tag. Tell me if it works.