Where does p:fileUpload save my file?

10,939

It stores it by default in the system default temp directory as identified by java.io.tmpdir system property. You could use UploadedFile#getContents() or UploadedFile#getInputStream() to get the file contents and write it to the desired folder. But you can also change the default upload location by an initialization parameter of the filter.

Put this inside the <filter> element of the file upload filter:

<init-param>
    <param-name>uploadDirectory</param-name>
    <param-value>/path/to/uploads</param-value>
</init-param>

Note that when you're running Windows, it will be relative to the disk from where the webserver is started. So if it's C:\, then the above init param will actually resolve to C:\path\to\uploads. You should also make sure that this folder is already been prepared beforehand and thus exists and is writable.

Share:
10,939
user1404693
Author by

user1404693

Updated on June 17, 2022

Comments

  • user1404693
    user1404693 almost 2 years

    I have a p:fileUpload function on my page and every time I upload a file I cannot seem to find it in the folder specified in my web.xml file.

    I have added the following jars to my library: primefaces-3.2.jar commons-io-2.3.jar commons-fileupload-1.2.2.jar

    Here is my web.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    
        <filter> 
            <filter-name>PrimeFaces FileUpload Filter</filter-name> 
            <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> 
        <init-param> 
            <param-name>uploadDirectory</param-name> 
            <param-value>C:\Users\SomeUser\Documents\NetBeansProjects\System\Upload\</param-value> 
        </init-param> 
        <init-param> 
            <param-name>thresholdSize</param-name> 
            <param-value>1000000</param-value> 
        </init-param> 
        </filter>
    
        <filter-mapping>
            <filter-name>PrimeFaces FileUpload Filter</filter-name>
            <servlet-name>Faces Servlet</servlet-name>
        </filter-mapping>
    
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
    
        <error-page>
            <error-code>404</error-code>
            <location>/404.jsf</location>
        </error-page>
    
        <context-param>  
        <param-name>primefaces.THEME</param-name>  
        <param-value>aristo</param-value>  
    </context-param>  
    
    </web-app>
    

    I am using the following: PrimeFaces 3.2, JSF 2.0 and GlassFish 3.1.1

    Any help will be appreciated. Thanks