Friday, June 10, 2022

Access Document and Media Files in Custom Portlet

  

Today we will discuss how we can display files which are stored in document and media portlet of Liferay.We also create download link so that user can download the files which are stored in document and media . Here i am using Liferay 7.3.

So lets start this step by step :-


For this i created a folder with name Testing and upload 2 files in it. 






Step 1:- Create a simple MVC Portlet

Create a simple Liferay module Project and provide the portlet name as DocumentAndMediaPortlet and paste this content:-


DocumentAndMediaPortlet.java


Explanation :

Here i am using DLAppService which provide as all the required methods. We get the List of files are present in Testing folder and put in request. 


Step 2:- Change view.jsp

Now change the view.jsp so that we can display all the files using search container.

view.jsp

Explanation:

By default size is in digits like 123, 6787 so we need to format it so that it should formatted in MB or KB. 

For this we use  LanguageUtil  class . I created a separate utility class that format the size and give us URL for download. 


Step 3:- Create Utility Class

Now create a utility class DocumentAndMediaUtil and paste this:-

DocumentAndMediaUtil.java


Step 4:- Check Output

Deploy your portlet and add to page.


Project Structure


You can download the source code from  here.

Related Post:-


No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!