Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the download url for a document library content programmatically

Tags:

liferay

I have several contents in my document library (images, documents, videos...) and I want to obtain the download url for each of them programmatically, so I can show them on a jsp in a custom portlet.

Investigating, I have found this page with a possible solution: https://www.liferay.com/community/forums/-/message_boards/message/11073293 but I'm not comfortable with it, since it implies building the url manually with several parameters.

I would like to know if there is a better way ("Liferay way") to do this.

like image 224
stoldark Avatar asked Aug 13 '12 09:08

stoldark


2 Answers

I am afraid but that is the liferay way :-).

If you still need more confirmation check out source code of the DLUtil#getPreviewURL method.

This method has been used by liferay's Documents & Media portlet and Document and Media display portlet. Also you can check-out the JSP source as to how these portlets use the above method /portal-web/docroot/html/portlet/document_library/action/download.jspf .

P.S.:
You can convert DLFileEntry to FileEntry with this static method.

like image 63
Prakash K Avatar answered Oct 28 '22 08:10

Prakash K


By such questions I see always to Liferay sources. Here is the fragment that build the file download url in "Documents and Media Library" portlet:

<liferay-ui:input-resource
   url='<%= themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + themeDisplay.getScopeGroupId() + StringPool.SLASH + fileEntry.getUuid() %>'
/>

but you are right, i would prefer a methode like DLFile.getUrl() too.

like image 28
Mark Avatar answered Oct 28 '22 07:10

Mark