Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liferay from fileentry to java file object

Anyone know how to retrieve a contentStream from a DLFileEntry (http://docs.liferay.com/portal/6.0/javadocs/com/liferay/portlet/documentlibrary/model/DLFileEntry.html) using an httpservlet?

I tried using DLFileEntry.getContentStream() but it fails giving me the error

com.liferay.portal.security.auth.PrincipalException: PermissionChecker not initialized

I solved in part that problem setting hardcode my userId:

long userId=2

            PrincipalThreadLocal.setName(userId);

            User user = UserLocalServiceUtil.getUserById(userId);

            PermissionChecker permissionChecker;

                permissionChecker = PermissionCheckerFactoryUtil.create(user, false);

            PermissionThreadLocal.setPermissionChecker(permissionChecker);

The problem of this solution is how to get the real userId, and how happen if the user is a guest?

I tried Long.parseLong(req.getRemoteUser()); but fail also.

like image 400
Sabrina Avatar asked Sep 02 '25 09:09

Sabrina


1 Answers

DLFileEntryLocalServiceUtil.getFile(userId, fileEntryId, version, incrementCounter) 

gives you the File. Did you try using this?

like image 62
Ravi Kumar Gupta Avatar answered Sep 04 '25 22:09

Ravi Kumar Gupta