Problem with form enctype="multipart/form-data"

thumbnail
Richard Kosegi, modified 13 Years ago. New Member Posts: 19 Join Date: 9/5/11 Recent Posts
Hi liferay folks,

I have problem with such form.When I add enctype="multipart/form-data" to allow file uploads,
GetterUtil.getLong(actionRequest.getParameter("itemId")) returns allways zero (also title is empty).

Without enctype it works just fine, but I can not upload file.

What I'm missing in my code?

edit_item.jsp

<%
long itemId = 10;
String title = "Test";
%>

<liferay-portlet:actionurl name="updateItem" var="updateItemURL">
</liferay-portlet:actionurl>

	<aui:form action="<%= updateItemURL %>" method="post" name="fm" enctype="multipart/form-data">
		<aui:input name="itemId" type="hidden" value="<%= String.valueOf(itemId) %>" />
                <aui:input name="itemLogo" type="file" label="stock.item.label.file" />
		<aui:button-row>
			<aui:button class="aui-button-input" type="submit" value="<%= title  %>" />
		</aui:button-row>			
	</aui:form>


StockPortlet.java

public void updateItem(ActionRequest actionRequest, ActionResponse actionResponse)
			throws IOException, PortletException {
		
		actionResponse.setRenderParameter("jspPage", "/jsp/stock/view_items.jsp");

		ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
		String title = GetterUtil.getString(actionRequest.getParameter("title"));
		long itemId = GetterUtil.getLong(actionRequest.getParameter("itemId"));

        }

thumbnail
Richard Kosegi, modified 13 Years ago. New Member Posts: 19 Join Date: 9/5/11 Recent Posts
OK, I figure it out.

I need to use this:

UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
long itemId = ParamUtil.getLong(uploadRequest,"itemId");

instead of

long itemId = GetterUtil.getLong(actionRequest.getParameter("itemId"));
josmar javier Alarcon Bothia, modified 13 Years ago. New Member Posts: 6 Join Date: 2/11/13 Recent Posts
good morning, hey I have the same problem, implement what you commented on the UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest (ActionRequest), but I want to take the value of a text box, you know this to be due or q can happen ?
thumbnail
Manish Yadav, modified 13 Years ago. Expert Posts: 493 Join Date: 5/26/12 Recent Posts
Hi Bothia
Might be this code will help you

JSP

public void sendEmail(ActionRequest request, ActionResponse response) {
   UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
   File file = uploadRequest.getFile("file");
   String email = ParamUtil.getString(uploadRequest, "fromemail");
}
giacomo savino, modified 12 Years ago. Junior Member Posts: 37 Join Date: 6/17/11 Recent Posts
Manish Yadav:
Hi Bothia
Might be this code will help you

JSP

public void sendEmail(ActionRequest request, ActionResponse response) {
   UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
   File file = uploadRequest.getFile("file");
   String email = ParamUtil.getString(uploadRequest, "fromemail");
}



Thank you
thumbnail
Asif Billa, modified 11 Years ago. New Member Posts: 15 Join Date: 5/4/15 Recent Posts
Thanks Richard,

I was facing the same problem.
I applied your approach and it get solved. emoticon