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?
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.
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