Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces Fileupload on Wildfly

I am trying to save a profile image in a database.

Page:

<p:graphicImage id="profileImage"
                        value="#{myProfile.usersProfileImage}" />    
<p:fileUpload fileUploadListener="#{myProfile.fileUploadListener}"
                            auto="true" mode="advanced" update="profileImage"
                            sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />

Backing:

public StreamedContent getUsersProfileImage() {
            return new DefaultStreamedContent(new ByteArrayInputStream(
                    user.getProfileJpegImage()));
    }    
public void fileUploadListener(FileUploadEvent event) {
        try {
            setProfileImageFromInputStream(event.getFile().getInputstream());
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    private void setProfileImageFromInputStream(InputStream stream) {
        try {
            user.setProfileJpegImage(IOUtils.toByteArray(stream));
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

After choosing a picture the picture does not change and I got following error in my console

14:36:02,387 ERROR [io.undertow.request] (default task-2) UT005005: Cannot remove uploaded file C:\Development\wildfly-8.0.0.Final\standalone\tmp\myApp.war\undertow3307538071115388117upload

I also found this issue https://issues.jboss.org/browse/WFLY-2329

and I also tried to extend my Faces Servlet with a multipart-config like:

<servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <multipart-config>
            <max-file-size>20848820</max-file-size>
            <max-request-size>418018841</max-request-size>
            <file-size-threshold>1048576</file-size-threshold>
        </multipart-config>
    </servlet>

but nothing changed.

Any ideas? TY in advanced

like image 970
DCO Avatar asked Mar 17 '14 13:03

DCO


2 Answers

I got the same error:

[io.undertow.request] (default task-62) UT005005: Cannot remove uploaded file...

However I could solve this issue by closing the stream after reading.

Here is my chunk of code (it is a little different):

    byte[] bytes;
    try {
        InputStream is = upFile.getInputstream();
        if (is != null) {
            bytes  = IOUtils.toByteArray(is);
            is.close();
        } else {
            bytes = new byte[0];
        }
    } catch (IOException e) {
        log.error(e.getMessage());
        bytes = new byte[0];
    }

After adding line:

    is.close();

the udertow error UT005005 was gone.

like image 127
Mitja Gomboc Avatar answered Oct 15 '22 11:10

Mitja Gomboc


I forgot to set the mimetype in StreamedContent

like image 1
DCO Avatar answered Oct 15 '22 09:10

DCO