Liferay 6: Get DLFileEntry download URL

Just below a very useful snippet, it generates the download/preview URL of a document from Liferay document library.

// Get file entry from DB (here we get it by its AssetEntry instance)
FileEntry fileEntry = DLAppServiceUtil.getFileEntry(assetEntry.getClassPK());

// Get last version of the file entry
FileVersion fileVersion = fileEntry.getFileVersion();

// Get ThemeDisplay instance 
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

// If you want to add additional GET parameters you can modify this var
String queryString = “”;

// Append the requested file version as GET parameter
boolean appendFileEntryVersion = true;

// Choose to prefix or not the URL by the portal URL
boolean useAbsoluteURL = true;

// Compute the download URL of the file entry 
String dlURL = DLUtil.getPreviewURL(fileEntry, fileVersion, themeDisplay, queryString, appendFileEntryVersion, useAbsoluteURL);

2 thoughts on “Liferay 6: Get DLFileEntry download URL

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.