We already know a lot of kinds of processing file upload code, more typical such as Apache famous FileUpload, of course, Liferay for us have considered, we can use Liferay upload files with the API to deal with file upload problem, This core interface is the Com.liferay.portal.kernel.upload.UploadPortletRequest interface.
For the simplest example, we're going to upload a file into the portlet on the Portlet page, and then the portlet will move the file to another location:
So, on the page (like config.jsp), we have to represent a file upload control with a <input type= "file" >:
<td>
<label><liferay-ui:message key= "Rslaunch.zipfile"/></label>
<div>
<input class= "Lfr-input-text" name= "Zip" type= "file"/>
<input name= "<portlet:namespace/> <%=constants.cmd%> "type=" hidden "value=" <%=Constants.UPDATE%> "/>
</div>
</td >
Then, in our Java code, we use the Uploadportletrequest interface to process the uploaded files:
/** * method used to upload the "target by reading" Server details from the properties * @param actio Nrequest * @throws Exception */public static void Uploadfiletodest (Actionrequest actionrequest) throws exc eption{if (logger.isdebugenabled ()) {Logger.debug ("FILEOPERATIONHELPER:UPL
Oadfiletodest () ");
} portletpreferences Preferences = Portlethelper.getportletpreferences (actionrequest);
String Portletinstanceid = Preferences.getvalue (rs_launch_portlet_preference_portlet_id, StringPool.DOUBLE_QUOTE);
String Fileoriginfolder = Configutil.getproperty (Rs_launch_zip_origin_folder);
Uploadportletrequest uploadrequest = portalutil.getuploadportletrequest (actionrequest);
String fileName = Uploadrequest.getfilename (rs_launch_config_page_form_zip_input_name); File tempfile = Uploadrequest.getfile (rs_launch_config_page_form_zip_input_name); ...
As you can see from the code here, we get a Uploadportletrequest object in line 15th and then use its AP to get the file name (16 lines) right and get the file object, then the operation of this file is normal I/O operations, we are omitted here.