How to Upload Documents and Files in Liferay


Today we will discuss how to upload documents and files in Liferay. For this we will use Document and Media Portlet of Liferay. We already discuss all method in detail. Here we create a application where user can browse the documents and upload the documents and also able to download the uploaded documents. Before reading this blog it is highly recommended to read my previous blogs on Document and Media Portlet in Detal and  Upload Documents Programatically in Liferay .

So lets start this step by step:-

Step 1:-Create Liferay Project and Portlet
Create a Liferay Project in eclipse and then create a MVC portlet in the Project.For theses you may refer Step 1 and Step 2 of my previous blog Here .





Step 2:-Create Your Form
Open view.jsp and paste this code:-


Explanation:-


  • Here in form we use enctype="multipart/form-data". If we provide functionality of upload file than we have to change the enctype default value is application/x-www-form-urlencoded. For detail you may visit here.
  • name="uploadedFile" this attribute is used to fetch mimeType, location of file etc. in java code.


Step 3:-Create portlet.properties
Create a property file in src with name portlet.properties and paste this content:-



Step 4:-Entry for thumbnails
If file is too large liferay not created thumbnail because default maximum size for thumbnail creation of file is 100MB only.Due to this a error comes as "File is too large for preview or thumbnail generation ".So open portal-ext.properties and paste this line and restart the Server.

dl.file.entry.previewable.processor.max.size=-1 


Step 5:-Create method in Java Class
Open your Java class and Paste this Content:-


Explanation:-


  • Here we fetch all the information related to file by UploadPortletRequest object and passing "uploadedFile" which is same as name attribute in our view.jsp for input type file.
  • All the method used in this class are already explained in my previous blog you can check it Here

Note:-

If your form contain both file and fields like text field than you have to get it by passing "UploadPortletRequest " Object. Ex:-
Like we have a form with file and text box name email. Than

ParamUtil.get(actionRequest,"email") always return null

You must use this:-

ParamUtil.get(uploadPortletRequest ,"email");


Step 6:-Create download.jsp
Create a jsp file download.jsp that contain all the links to uploaded files that belong to a particular folder.


Explanation:-

Here we use jstl tags so for using jstl we have to provide entry in liferay-plugin-package.properties as :-

portal-dependency-jars=\
    jstl-api.jar,\
    jstl-impl.jar

Step 7:-Check Output
Now deploy your portlet add to page and Check the output as:-




Project Structure:-





You can Download Source code from How to Upload Documents and Files in Liferay.

Hope this will Help....