Finally, I was able to figure it out. The Commons-fileuploads parseRequest(httpServletRequest) tries to read the inputStream request. Since the container has already read it, it is empty. So what can be done to solve this problem? The answer is a bit more complicated than I originally thought. First you need your own FileUploadFilter file, which might look like this:
public class FileUploadFilter implements Filter { private final static Logger LOGGER = LoggerFactory.getLogger(FileUploadFilter.class); @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; boolean isMultipart = (httpServletRequest.getContentType() == null) ? false : httpServletRequest.getContentType().toLowerCase().startsWith("multipart/"); if (isMultipart) { MultipartRequest multipartRequest = new MultipartRequest(httpServletRequest); LOGGER.info("File upload request parsed succesfully, continuing with filter chain with a wrapped multipart request"); filterChain.doFilter(multipartRequest, response); } else { filterChain.doFilter(request, response); } } @Override public void destroy() { LOGGER.info("Destroying UploadFilter"); }
Next: register this filter in your web.xml and remove / replace the Primefaces filter. It should look something like this:
<filter> <filter-name>FileUpload Filter</filter-name> <filter-class><YourPackage>.FileUploadFilter</filter-class> </filter> <filter-mapping> <filter-name>FileUpload Filter</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping>
Unfortunately, this is not the case. You will need your own MultipartRequest, since you will have to compile a list of FileItems yourself. But stop. We must work with javax.servlet.Part classes that are not compatible with FileItem. So I wrote a new class that connects the two. You can find this class here: http://pastebin.com/JcfAYjey
The final piece of the puzzle is the mentioned MultipartRequest, which links PartItem and FileUploadFilter. I took this class from Primefaces-Repository and changed it as needed (see http://pastebin.com/Vc5h2rmJ ). The difference between lines 47 and 57.
So what you need to do: 1. Create three classes FileUploadFilter, MultipartRequest and PartItem 2. Register the file FileUploadFilter in your web.xml 3. Enjoy!
PLEASE PAY ATTENTION: this is not intended as a solution to solve all problems, but simply a direction that you can take in further implementations. For example, MultipartRequest will only work for parts with the image/* content type. You may need to change this.
Feel free to change the code;) I hope this helps!
EDIT: I forgot to mention one important step. You will also need your own FileIUploadRenderer. The implemented Primefaces use instanceof checking to find MultipartRequest. Since you are using another option, the import must be changed. The rest of the class may remain unchanged ( http://pastebin.com/rDUkPqf6 ). Remember to register it inside your faces-config.xml:
<render-kit> <renderer> <component-family>org.primefaces.component</component-family> <renderer-type>org.primefaces.component.FileUploadRenderer</renderer-type> <renderer-class><YourPackage>.FileUploadRenderer</renderer-class> </renderer> </render-kit>