Reputation: 267
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.
Upvotes: 4
Views: 8474
Reputation: 1798
DLFileEntryLocalServiceUtil.getFile(userId, fileEntryId, version, incrementCounter)
gives you the File. Did you try using this?
Upvotes: 3
Reputation: 2193
Please use PermissionThreadLocal.getPermissionChecker() to get the permissionChecker object of the current logged in user with current state. If the user is guest, still you will get the permissionChecker object.
-Felix
Upvotes: 0
Reputation: 2683
If you're using Liferay 6.1 then the following code will get you a InputStream for the That DLFileEntry.
InputStream inputStream = DLFileEntryLocalServiceUtil.getFileAsStream(fileEntry.getUserId(), fileEntry.getFileEntryId(), fileEntry.getVersion());
Howwever the error you're getting is seems to be due you not authenticating with Liferay before making this call to the server.
How are you calling this code?
Upvotes: 0