stoldark
stoldark

Reputation: 444

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

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.

Upvotes: 9

Views: 27789

Answers (2)

Prakash K
Prakash K

Reputation: 11698

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.

Upvotes: 8

Mark
Mark

Reputation: 18797

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.

Upvotes: 7

Related Questions