Greetings community!
I pose the following problem, I have an image in a BBDD (format bytea[]
) and I want to serve an answer to show that image in my HTML. I do not have routes or directories, just the image in the database.
It looks something like this:
cUpload.dameFoto () // returns my image in inputStream format.
I have tried to change the ContentType with image format "imagen/jpg"
but I can not get the output in my javascript . Thanks in advance for your collaboration
public void doPost(HttpServletRequest request, HttpServletResponse response){
OutputStream out;
BufferedImage bI;
int nRead;
InputStream is;
try {
response.setContentType("multipart/form-data");
out = response.getOutputStream();
is = cUpload.dameFoto();
bI = ImageIO.read(is);
ImageIO.write(bI, "png", out);
} catch (IOException | ServletException e) {
System.err.println("Error en la respuesta de salida uploadServlet: " + e.getMessage());
}
}