RE: Primefaces 6.2 fileUpload thresholdSize setting on Liferay 7.0 GA7

thumbnail
William Gosse, modified 5 Years ago. Liferay Master Posts: 533 Join Date: 7/4/10 Recent Posts
So I got a Primefaces portlet with a p:fileUpload tag in it. Everything seems to work fine without having to modify my web.xml or pom.xml file to include fileUpload specific stuff.  I was hoping the include the thresholdSize parameter in my web.xml in order not write files to disk that when they're less then 1mb.  However I'm not finding the magic sauce yet to make that work.  I first tried adding the following to my web.xml file:
&nbsp;&nbsp; &nbsp;<context-param>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<param-name>primefaces.UPLOADER</param-name>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<param-value>commons</param-value>
&nbsp;&nbsp; &nbsp;</context-param>
&nbsp;&nbsp; &nbsp;<servlet>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<servlet-name>Faces Servlet</servlet-name>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<load-on-startup>1</load-on-startup>
&nbsp;&nbsp; &nbsp;</servlet>
&nbsp;&nbsp; &nbsp;<filter>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<filter-name>PrimeFaces FileUpload Filter</filter-name>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<filter-class>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;org.primefaces.webapp.filter.FileUploadFilter
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</filter-class>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<init-param>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<param-name>thresholdSize</param-name>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<param-value>1000000</param-value>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;</init-param>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;&nbsp; &nbsp;</filter>
&nbsp;&nbsp; &nbsp;<filter-mapping>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<filter-name>PrimeFaces FileUpload Filter</filter-name>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<servlet-name>Faces Servlet</servlet-name>
&nbsp;&nbsp; &nbsp;</filter-mapping>
Of course the servlet tag was already there but my files still get written to liferay's tomcat's temp folder. So I tried adding the following to my .xhtml view file
<h:form id="taskForm" enctype="multipart/form-data"         onkeypress="if (event.keyCode == 13) { return false; }">
</h:form>
This ensures the encoding type is multipart for the form enclosing the fileUpload.  I didn't to need before as well.I also tried adding the following to my portlet pom.xml:
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<dependency>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupid>commons-fileupload</groupid>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactid>commons-fileupload</artifactid>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>1.3.1</version>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <optional>true</optional>
&nbsp; &nbsp; &nbsp; &nbsp; </dependency>
&nbsp; &nbsp; &nbsp; &nbsp; <dependency>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupid>commons-io</groupid>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactid>commons-io</artifactid>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>2.4</version>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <optional>true</optional>
&nbsp; &nbsp; &nbsp; &nbsp; </dependency>

None of these changes seem to help to stop the upload files from getting temporarily stored in the file system. Finally here's what my fileUpload tag looks like:
<p:fileupload id="extractionCSVUpload"       update=":taskForm:tasksTable"  rendered="#{tasksView.selectedTask.reviewType == 'csv'}"  disabled="#{tasksView.selectedTask == null || tasksView.isCurrentAssignee() == false}"  fileUploadListener="#{tasksView.handleFileUpload}"  mode="advanced" skinSimple="true" auto="true" label="CSV" />
​​​​​​​
Any help would be greatly appreciated.
thumbnail
Neil Griffin, modified 5 Years ago. Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
Hi Bill,
Apologies, but in-memory file upload isn't supported. :-(
Liferay Faces Bridge takes the responsibility of handling the file upload for all supported component suites. In the case of PrimeFaces, we decorate the p:fileUpload renderer and prevent PrimeFaces from trying to handle it.
For Portlet 2.0, Liferay Faces Bridge relies on Commons-Fileupload to get the job done. Although it has a "threshold" feature for in-memory file uploads, we specifically don't support it. For more info, see MultiPartFormDataProcessorCompatImpl.java lines 90-92.
When the Portlet 3.0 release is done, Liferay Faces Bridge will rely on the ClientDataRequest.getPart() feature of the Portlet 3.0 API, which further encapsulates/hides the file upload implementation from the JSF portlet application.
Best Regards,
Neil
thumbnail
William Gosse, modified 5 Years ago. Liferay Master Posts: 533 Join Date: 7/4/10 Recent Posts
Thanks Neil.  This definitely clarifies what I've been seeing. I can't I didn't know this before.
thumbnail
William Gosse, modified 5 Years ago. Liferay Master Posts: 533 Join Date: 7/4/10 Recent Posts
The Liferay upload related properties seem to have no effect either. Is that true?
thumbnail
Neil Griffin, modified 5 Years ago. Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
Hi Bill,
There are three different options you can specify in either web.xml (affects all portlets) or portlet.xml (affects individual portlets):

1) com.liferay.faces.util.uploadedFileMaxSize
https://github.com/liferay/liferay-faces-util/blob/master/src/main/java/com/liferay/faces/util/config/WebConfigParam.java#L89

2) com.liferay.faces.bridge.uploadedFileMaxSize

3) javax.faces.UPLOADED_FILE_MAX_SIZE

https://github.com/liferay/liferay-faces-bridge-impl/blob/master/bridge-impl/src/main/java/com/liferay/faces/bridge/internal/PortletConfigParam.java#L117
#1 wins over #2 and #3. #2 and #3 are effectively synonyms.

Neil​​​​​​​
thumbnail
William Gosse, modified 5 Years ago. Liferay Master Posts: 533 Join Date: 7/4/10 Recent Posts
Just as a side note it be useful if the following could be added into the bridge as well:
Set the threshold size to prevent extraneous serialization of uploaded data.Defaults:
    com.liferay.portal.upload.LiferayFileItem.threshold.size=262144
Set the temp directory for uploaded files.Examples:
    com.liferay.portal.upload.UploadServletRequestImpl.temp.dir=C:/Temp
thumbnail
William Gosse, modified 5 Years ago. Liferay Master Posts: 533 Join Date: 7/4/10 Recent Posts
Thanks again Neil.