In Liferay Portal, Web Form Portlet is used to create custom forms but the types of field that can be created are limited. One such missing field type is File Upload Control. It’s a common requirement to have file upload control in forms.
Following are the steps to add File Upload Control to Web Form Portlet -
1. Add a new field type to edit_field.jsp
<aui:option selected='<%= fieldType.equals("file") %>' value="file"><liferay-ui:message key="file" /></aui:option>
2. Accordingly update the view.jsp to render the your new field
<c:when test='<%= fieldType.equals("file") %>'>
<aui:input cssClass='<%= fieldOptional ? "optional" : StringPool.BLANK %>' label=" <%=HtmlUtil.escape(fieldLabelDisplay) %>" name="<%= fieldName %>" type="file" value="<%=HtmlUtil.escape(fieldValue) %>"/>
</c:when>
3. Set the preferences for this field in ConfigurationActionImpl.java
boolean isFileUpload = false;
if ("file".equals(fieldType)) {
isFileUpload = true;
}
preferences.setValue("isFileUpload", String.valueOf(isFileUpload));
4. Finally get the file in WebFormPortlet.java and proceed with your implementation…
File file = uploadRequest.getFile(paramName.toString());
Proceed we the implementation with file object for example save to document library, send in mail etc.