Primefaces FileUpload not working in Spring Boot

瘦欲@ 提交于 2019-11-30 22:04:40
Xtreme Biker

Finally, I got it working using the Apache Commons library. Similarly that what we might do in a standard web.xml file, that's my context initializer:

@Bean
public ServletContextInitializer initializer() {
    return new ServletContextInitializer() {
        @Override
        public void onStartup(ServletContext servletContext)
                throws ServletException {
            servletContext.setInitParameter("primefaces.THEME", "bluesky");
            servletContext.setInitParameter(
                    "javax.faces.FACELETS_SKIP_COMMENTS", "true");
            servletContext.setInitParameter(
                    "com.sun.faces.expressionFactory",
                    "com.sun.el.ExpressionFactoryImpl");
            servletContext.setInitParameter("primefaces.UPLOADER",
                    "commons");
        }
    };
}

I explicitly tell Primefaces to use the commons uploader, like said in docs (the other choice is to use native, which is not working).

Then, just adding this two dependencies to the project, we're ready to go:

<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3</version>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.2</version>
</dependency>

I keep the thread opened for some response based in the native mode.

See also:

It could be also necessary to transfer xml filter configuration to Java-based Config :

<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

to your @Configuration

@Bean
public FilterRegistrationBean FileUploadFilter() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(new org.primefaces.webapp.filter.FileUploadFilter());
    registration.setName("PrimeFaces FileUpload Filter");
    return registration;
}

in combination with the above answer it work for me

Just to put my two cents, with Spring boot 1.4.2.RELEASE, Primefaces 6.0, OCP Soft rewrite 2.0.12.Final, JSF 2.1.29-08 and application deployed on Tomcat 8, I also need to disable spring hiddenHttpMethodFilter.

@Bean
public FilterRegistrationBean hiddenHttpMethodFilterDisabled(
        @Qualifier("hiddenHttpMethodFilter") HiddenHttpMethodFilter filter) { 
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(filter);
    filterRegistrationBean.setEnabled(false);
    return filterRegistrationBean;
}

I have spent with this issue almost two days and as last thing I have tried to disable spring filters one by one, so I hope it will help someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!