Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Obtain Download-URL for DL-File
Hey Everybody,
I have a problem getting a download-URL for an element of the document-library.
First I did it that way:
Java
JSP:
It worked when trying to download a file inside the same site - but now I placed the portlet to download the file inside "my-dashboard", which is a group-site - and then the ressource cannot be found
. It is not a matter of rights - the URL seems not to be generated in the right way.
Can someone help me to generate an URL when I have the FileEntry Object or its ID - no matten in what site I am?
Also tried that one :
Doesnt seem to work either
I also have the group/site ID - but how to use it to generate the URL?
Thanks in advance!
Regards, Heiko
I have a problem getting a download-URL for an element of the document-library.
First I did it that way:
Java
DLFileEntry fe = DLFileEntryLocalServiceUtil.getDLFileEntry( readingConfirmation.getDocumentId() );
fileEntryUUId = fe.getUuid()
JSP:
<a href="<%= themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + themeDisplay.getScopeGroupId() + StringPool.SLASH + fileEntryUUId %>"></a>
It worked when trying to download a file inside the same site - but now I placed the portlet to download the file inside "my-dashboard", which is a group-site - and then the ressource cannot be found

Can someone help me to generate an URL when I have the FileEntry Object or its ID - no matten in what site I am?
Also tried that one :
DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK, false, true)
Doesnt seem to work either

I also have the group/site ID - but how to use it to generate the URL?
Thanks in advance!
Regards, Heiko
Hey,
I found a solution that seems to work :
I found a solution that seems to work :
String url = portalURL + "/c/document_library/get_file?uuid=" + document.getUuid() + "&groupId=" + document.getGroupId();
Zsolt - Jácint Balogh, modified 10 Years ago.
Junior Member
Posts: 91
Join Date: 10/9/13
Recent Posts
Hi,
This worked for me:
Regards,
Zsolt
This worked for me:
public static String getDLFileURL(DLFileEntry file) {
return "/documents/" + file.getGroupId() + BACKSLASH + file.getFolderId() + BACKSLASH
+ file.getTitle() + BACKSLASH + file.getUuid();
}
Regards,
Zsolt
Freemarker solution?
Here's one solution, it depends a bit, where you start. If you already have a fileentry, you also can use the approach above and concatenate the url yourself. It works pretty well, I have used that approach now for years, never run into problems.
If you have just an ADT, some numbers, an assetentry, ... you need to use the serviceLocator:
https://bitbucket.org/snippets/mrg3kko/pebq6x/liferay-71-adt-get-download-url-for-a
Another approach is to use a Template Context Contributor:
It allows you to inject services into ADTs. You could simply write ${myhelpercontributor.getURLForFile(entryId)} to get the url.
https://help.liferay.com/hc/en-us/articles/360018170931-Template-Context-Contributor
Please note that it only works "as expected" from 7.0.0 DXP SP7 and up:
https://issues.liferay.com/browse/LPS-76631
If you have just an ADT, some numbers, an assetentry, ... you need to use the serviceLocator:
https://bitbucket.org/snippets/mrg3kko/pebq6x/liferay-71-adt-get-download-url-for-a
Another approach is to use a Template Context Contributor:
It allows you to inject services into ADTs. You could simply write ${myhelpercontributor.getURLForFile(entryId)} to get the url.
https://help.liferay.com/hc/en-us/articles/360018170931-Template-Context-Contributor
Please note that it only works "as expected" from 7.0.0 DXP SP7 and up:
https://issues.liferay.com/browse/LPS-76631
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™