Reputation:
I want to retrieve a user profile picture. How do i do it? Could you please share a code snippet? Im using Liferay 6.0.6. It has only user.getPortraitId() and no user.getPortraitURL(). So once i get the portrait id inside a JAVA class, what do i do with it?
Upvotes: 3
Views: 8387
Reputation: 1568
There are at least two options on rendering portraits in JSP:
<img src="<%= themeDisplay.getPathImage()%>
/image_gallery?img_id=<%= image.getImageId()%>&t=
<%= ImageServletTokenUtil.getToken(image.getImageId())%>">
<img src="<%= themeDisplay.getPathImage() %>/user_portrait?img_id=<%=id %>">
The first approach contains additional security aspect based on security token which you may or may not find relevant to your needs.
Upvotes: 2
Reputation: 18827
See the implementation of UserConstants.getPortraitURL(...)
https://github.com/liferay/liferay-portal/blob/master/portal-service/src/com/liferay/portal/model/UserConstants.java
On this approach you can get the image url.
If you need the image object, you can load it with ImageLocalServiceUtil
:
long portraitId = user.getPortraitId();
Image image = ImageLocalServiceUtil.getImage(portraitId);
Upvotes: 3