Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Navin Agarwal
Unable to upLoad file from custom Portlet
October 3, 2012 5:57 AM
Answer

Navin Agarwal

Rank: Junior Member

Posts: 46

Join Date: January 20, 2011

Recent Posts

Hello,

I have written one portlet to upload the file to Document Library. bellow is the code.

JSP file
1
2<aui:form action="<%=actionURL%>" enctype="multipart/form-data" method="post"  >
3      
4       <aui:input name="user_id" label="User ID" disabled="true" value='${User_id }'/>
5       <aui:input name="file" inlineLabel="left" type="file" style="width: auto;"></aui:input>
6</aui:form>


File Upload Action file
 1
 2
 3public void processAction(
 4            ActionRequest actionRequest, ActionResponse actionResponse)
 5        throws IOException, PortletException {
 6       
 7        UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
 8        String sourceFileName =uploadRequest.getFullFileName("file"); //getFileName("file");
 9       
10       System.out.println("sourceFile Full  Name     " + sourceFileName);     // I am getting the sourceFile Full  Name  proper. When I am using enctype="multipart/form-data"
11        int userId = Integer.parseInt(actionRequest.getParameter("user_id"));          // here I am getting Error
12
13      }
14}


Console Log
sourceFile Full Name Fileupload.txt
Oct 3, 2012 10:07:44 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet createvisitportlet Servlet threw exception
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:417)
at java.lang.Integer.parseInt(Integer.java:499)
at com.navin.portal.portlet.FileUploadPortlet.processAction(FileUploadPortlet.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)


And when I am not using enctype="multipart/form-data" inside Form tag , I am able to get the other data's inside the form tag. Please help me !! emoticon
Vilmos Papp
RE: Unable to upLoad file from custom Portlet
October 3, 2012 6:35 AM
Answer

Vilmos Papp

LIFERAY STAFF

Rank: Liferay Master

Posts: 522

Join Date: October 21, 2010

Recent Posts

Hi,

If you need the current user then use themeDisplay to access it in your processAction method.

Regards,
Vilmos
Vilmos Papp
RE: Unable to upLoad file from custom Portlet
October 3, 2012 6:42 AM
Answer

Vilmos Papp

LIFERAY STAFF

Rank: Liferay Master

Posts: 522

Join Date: October 21, 2010

Recent Posts

If you check EditFileEntryAction.java you will see how to extract other parameters like:

1
2long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
3String sourceFileName = uploadPortletRequest.getFileName("file");


Hope it helps.
Navin Agarwal
RE: Unable to upLoad file from custom Portlet
October 3, 2012 11:43 PM
Answer

Navin Agarwal

Rank: Junior Member

Posts: 46

Join Date: January 20, 2011

Recent Posts

Hi Vilmos,

The issue is whenever , I am trying to get the and Integer, String , Float value from form inside the Process Action by using,
1
2 int foo = Integer.parseInt(actionRequest.getParameter("foo"));
3float fee = Float.parseFloat(actionRequest.getParameter("fee"));
4String remark = actionRequest.getParameter("remarks");
5


Even I have used ParamUtil .
1
2int foo = ParamUtil.getInteger(actionRequest, "foo");


In both above case I am getting Null value , This is because I am using enctype="multipart/form-data" inside view.jsp <FORM> tag for the file Upload.
Navin Agarwal
RE: Unable to upLoad file from custom Portlet
October 4, 2012 5:13 AM
Answer

Navin Agarwal

Rank: Junior Member

Posts: 46

Join Date: January 20, 2011

Recent Posts

Hi Vilmos,

Its helped me a lot . emoticon Its working .. I was using ActionRequest insight of uploadPortletRequest.


Vilmos Papp:
If you check EditFileEntryAction.java you will see how to extract other parameters like:

1
2long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
3String sourceFileName = uploadPortletRequest.getFileName("file");


Hope it helps.


Thanks a lot emoticon
Vilmos Papp
RE: Unable to upLoad file from custom Portlet
October 10, 2012 12:54 AM
Answer

Vilmos Papp

LIFERAY STAFF

Rank: Liferay Master

Posts: 522

Join Date: October 21, 2010

Recent Posts

That's great!

I'm glad it solved your problem.

Regards,
Vilmos

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!