Research on file uploading in Liferay portlets

Source: Internet
Author: User
Tags file upload

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.