0

I have a method which returns a byte array of an image. The problem is when i try to show it on the screen with StreamedContent i get Error in streaming dynamic resource.

imageBean:

BufferedImage bImage = ImageIO.read(new File("imagepath"));
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ImageIO.write(bImage, "png", bos );
        byte [] image = bos.toByteArray();
 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(image);
 imageContent = new DefaultStreamedContent(byteArrayInputStream, "image/png");

xhtml:

<p:graphicImage value="#{imageBean.imageContent}"></p:graphicImage>

Any idea how to fix it or why i am getting this error ?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
prof958
  • 13
  • 3
  • 1
    That actually looks to be a well reported problem, not necessarily something you are doing wrong but more of a design problem, this problem has already been approached and answer on another [post](https://stackoverflow.com/questions/8207325/display-dynamic-image-from-database-or-remote-source-with-pgraphicimage-and-str) – Tiago Carneiro Jun 17 '20 at 10:33
  • I suggest using a custom [ImageServlet](https://stackoverflow.com/questions/62226597/jsf-dynamic-image-as-div-background/62229394#62229394). This is better because you don't need to use the relative complex `p:graphicImage` and it is usable everywhere (css, js, etc.) – fuggerjaki61 Jun 17 '20 at 14:40
  • @fuggerjaki61: js, css etc via (image)servlet? Never had the need for it, overly complex – Kukeltje Jun 17 '20 at 17:45

0 Answers0