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
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 :

String url = portalURL + "/c/document_library/get_file?uuid=" + document.getUuid() + "&groupId=" + document.getGroupId();
thumbnail
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:


    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?
thumbnail
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