Saturday, July 18, 2015

Folder and File upload Programmatically in Document and Media Portlet of Liferay


In the previous tutorial we discuss how to add Folder and Documents in liferay by using GUI.Today we will discuss how to add Folder and Documents/Files in Document and Media Portlet by using API methods provided by liferay.

For this we have two set of classes:-
1)DL Services
2)DLApp Services

Any of the classes can used to achieve folder creation, file upload etc.But:-

DLFileEntry services and DLFolderEntry services are specifically for storing file and folder entries in liferay's database and are totally unaware of the new repository concept introduced in 6.1.

Where as DLApp (DLAppService & DLAppLocalService) services take into account these things i.e. to say that they take care of syncing documents between liferay database and other repositories,and not just store entries in Liferay database.

Here i am discussing both .Before reading this blog it is highly recommended to read my previous blog Document and Media portlet 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 Folder in Document and Media
Open you java Class and paste these methods:-


Explanation:-

1)As you can see createfolder() use DLAppServiceUtil and createDLFolder() use DLFolderLocalServiceUtil.
2)In createDLFolder method we have boolean mountPoint.
Run the method two times with both mountPoint values.



See the location of folder where they create.

Step 3:-Add Files to the Folder
Add the two methods and use any of these:-


Explanation:-

1)Here in fileUploadByDL method we use addFileEntry method to add the file in the folder but here file is save in draft mode so we use updateFileEntry method to change the mode from draft to approved.
2)Here if you click on image and message appears like "File is too large for preview or thumbnail generation" just go to portal-ext.properties add this line and restart the server:-

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

So thumbnail is generated for any size of file.






Step 4:-Get All Folders
Paste theses two methods.Here you see the difference between DL and DLApp methods:-


Explanation:-


1)Output by getAllDLFolder()

DLFolder Id >> 12304
DLFolder Name >>/12709
DLFolder Id >> 12505
DLFolder Name >>/12714
DLFolder Id >> 12333
DLFolder Name >>/12719
DLFolder Id >> 12401
DLFolder Name >>/12729
DLFolder Id >> 12702
DLFolder Name >>/12734
DLFolder Id >> 12766
DLFolder Name >>Liferayiseasy
DLFolder Id >> 12763
DLFolder Name >>MountPointFalse
DLFolder Id >> 12760
DLFolder Name >>MountPointTrue


2)Output by getAllFolder()

Folder Id >> 12766
Folder Name >>Liferayiseasy
Folder Id >> 12763
Folder Name >>MountPointFalse
Folder Id >> 12760
Folder Name >>MountPointTrue

Here you can see that DLAppServiceUtil give more specific results however DLFolderLocalServiceUtil give all the folders which are even deleted or in recycle bin.

Step 5:-Get a Particular Folder
Paste theses two methods and just provide the Folder name:-



Step 6:-Get download link for files in Folder
Paste this code and pass the folder name to the methods:-



In the next blog How to Upload file in Liferay we create a simple application that can browse the documents and upload in document and media portlet and we can download those documents by clicking on the links.

You can Download Source code from Folder and File upload Programmatically in Document and Media Portlet of Liferay

Hope this will Help....

No comments:

Post a Comment

Total Pageviews

Like Us on Facebook

Number Of Unique Visitor

Free counters!