Tuesday, October 17, 2017

Upload / Download Files in Liferay


We already know how to upload file in document and media  portlet. Today we will see how to upload a file in local machine . I created a folder on my desktop with name textdata. When we upload a file it will save in this folder . Here i also check that file must be a text file if you upload a pdf or jpeg it will give error.

So lets start this Step by Step:-

Step 1:-Create a project and portlet
Create a project and then create a portlet in it .Here my project name is upload-download-portlet and portlet name is Demo.






Step 2:-Change the jsp

Change your view.jsp as:-

view.jsp


Explanation:-
Here we create two urls :-
1)uploadURL:- Action URL for upload 
2)downloadURL:- Resource URL(Ajax) for Download

Here we also use success and failure messages for Validation.


Step 3:-Change the Controller(Java)
Change the Portlet file as:-

Demo.java


Explanation:-
Here i created a folder textData on Desktop where i upload the file. File are save with name hello.txt.

I used IOUtils class which belong to commons-io.jar so add this jar in liferay-plugin-package.properties.






Step 4:-Check the output
Now deploy the portlet and check the output:-


1)If you upload a pdf file:-


2)If you upload a text file:-



You can download the source code from here.


Hope this will Help....

Related Post:-


No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!