This is a short tutorial for those of you who want to upload a file using Liferay portlets. First you need to give your form in your JSP the correct encoding type:
<form
name="<portlet:namespace/>fm" method="post"
enctype="multipart/form-data" action="<portlet:actionURL
/>">
This makes sure that the data you upload is
really uploaded. Next you should add the upload button like this :
<input type="file"
name="<portlet:namespace/>yourfile"
id="<portlet:namespace/>yourfile" />
That´s all in the JSP. If you now add the
following in your processAction method, you have access to your uploaded file:
public void processAction(ActionRequest
request, ActionResponse response)throws PortletException, IOException {
UploadPortletRequest uploadRequest =
PortalUtil.getUploadPortletRequest(request);
String sourceFileName =
uploadRequest.getFileName("yourfile");
File file =
uploadRequest.getFile("yourfile");
No comments:
Post a Comment