Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I embed images from database into web pages

One possible way of storing images in a database is as a stream of bits. This works as a storage mechanism, but I can't figure out how to embed this data into a webpage as an image once I extract it to fulfill a client request.

I'm working with Servlets in Java. Can anyone give me some guidance?

like image 620
EpsilonVector Avatar asked Feb 17 '26 17:02

EpsilonVector


1 Answers

You probably want to write a servlet that reads the BLOB from the database and copies directly into HttpServletRequest.getOutputStream(), remembering to set the content type to the appropriate format (image/png for example).

The database id or key or whatever can be encoded in the path (/image/foo), or passed as a query parameter (/image?id=foo). This path is what you use in your <img> tag.

This is probably best written in actual Java, rather than JSP or similar presentation technologies.

like image 65
OrangeDog Avatar answered Feb 20 '26 03:02

OrangeDog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!