0

I am using an byte array byte[] to store images in my databse, using JPA:

@Lob @Basic(fetch = FetchType.LAZY)
@Column(length=16777000)
private byte[] image;

This is how I upload the images, before storing them in the database:

public void uploadFile(org.primefaces.event.FileUploadEvent event) {
    byte[] img = event.getFile().getContents();
    // and so on...
}

Then, I am reading the image from the database and want to display it using PrimeFaces/JSF. Something like:

<p:galleria value="#{bean.images}" var="image"
    panelWidth="500" panelHeight="313" showCaption="true">
        <p:graphicImage name="image"
            alt="Some description..." title="Some title..." />
</p:galleria>

To do that, I need to convert the byte[] array back to a displayable image. Does anybody know how to do this?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
John
  • 735
  • 2
  • 14
  • 32
  • John, in future JSF questions about problems which are **not** answerable with JLS nor reproducible using a plain Java SE application class with `main()` method, do **not** use [java] tag. If your question however is, then you should instead question the relevance of Java EE related tags such as [jsf] and [jpa]. – BalusC Apr 28 '16 at 14:07
  • OK BalusC, I will take care in future. – John May 02 '16 at 07:13
  • But anyway, there was an answer to my question and I would like to see it... – John May 02 '16 at 07:28
  • 1
    That answer didn't make any sense. It just writes the `byte[]` to a local disk file system file in unnecessarily convoluted way via `ImageIO`. The answerer didn't seem to understand anything from the question. – BalusC May 02 '16 at 07:31
  • Oh, I see. Thanks anyway. – John May 02 '16 at 08:13

0 Answers0