Message Boards
Obtain Download-URL for DL-File
Heiko Ottenbacher, modified 9 Years ago.
Obtain Download-URL for DL-File
New Member Posts: 20 Join Date: 9/5/14 Recent Posts
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 . 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 :
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
Heiko Ottenbacher, modified 9 Years ago.
RE: Obtain Download-URL for DL-File
New Member Posts: 20 Join Date: 9/5/14 Recent Posts
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 9 Years ago.
RE: Obtain Download-URL for DL-File
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
Lee Jordan, modified 3 Years ago.
RE: Obtain Download-URL for DL-File
Expert Posts: 449 Join Date: 5/26/15 Recent Posts
Freemarker solution?
Christoph Rabel, modified 3 Years ago.
RE: Obtain Download-URL for DL-File
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
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