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?
Asked
Active
Viewed 8,095 times
2 Answers
3
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);

Mark
- 17,887
- 13
- 66
- 93
-
Thanks a ton mark :) But how do i get the imagePath to use the getPortraitURL() implementation? Also, once i get the image object, how do i render it? – May 22 '12 at 16:50
-
imagePath = themeDisplay.getPathImage(); – Mark May 22 '12 at 21:05
-
Hi Mark, if i have to get imagePath using themeDisplay, i would have to be able to get themeDisplay first inside a "JAVA class".... I know that we could do that as follows: ThemeDisplay themeDisplay = ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY); But, what does 'request' stand for? Im not using an action class or a servlet to use the "request" – May 23 '12 at 10:48
-
And what do you use? Is it a portlet? – Mark May 23 '12 at 11:41
-
Mark i used the ImageLocalServiceUtil as you suggested and it worked... Thanks a ton :) – May 23 '12 at 17:01
2
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.

Michal M
- 1,521
- 14
- 35
-
1`ImageServletTokenUtil` was replaced by `WebServerServletTokenUtil` as of Liferay 6.1 – Lucas Nov 10 '15 at 15:56