Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can get the uploaded file content via <code>FileUploadEvent</code>. In PrimeFaces 4.x with Apache Commons FileUpload, or in PrimeFaces 5.x with context param <code>primefaces.UPLOADER</code> set to <code>commons</code>, you can use <code>UploadedFile#getContents()</code> to obtain the uploaded file as <code>byte[]</code>.</p> <pre><code>public void handleFileUpload(FileUploadEvent event) { byte[] content = event.getFile().getContents(); // ... } </code></pre> <p>In PrimeFaces 5.x with context param <code>primefaces.UPLOADER</code> absent or set to <code>auto</code> or <code>native</code> while using JSF 2.2, then <code>getContents()</code> will return <code>null</code> as that's <a href="https://github.com/primefaces/primefaces/blob/5.1.x/src/main/java/org/primefaces/model/NativeUploadedFile.java" rel="nofollow noreferrer">not implemented in <code>NativeUploadedFile</code> implementation</a>. Use <code>UploadedFile#getInputStream()</code> instead and then <a href="https://stackoverflow.com/questions/1264709/convert-inputstream-to-byte-array-in-java">read bytes from it, e.g. with help of commons IO</a>.</p> <pre><code>public void handleFileUpload(FileUploadEvent event) { byte[] content = IOUtils.toByteArray(event.getFile().getInputstream()); // ... } </code></pre> <p>Finally, just set this <code>byte[]</code> in your entity and persist/merge it.</p> <p>Make sure that you have set the form encoding type to <code>multipart/form-data</code> and, when using the Apache Commons FileUpload, that you have configured the <a href="https://stackoverflow.com/questions/8875818/how-to-use-primefaces-pfileupload-listener-method-is-never-invoked/8880083#8880083">file upload filter</a> in <code>web.xml</code> as per PrimeFaces user guide.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload