How to retrieve a user profile picture in Liferay

怎甘沉沦 提交于 2019-12-21 21:05:48

问题


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?


回答1:


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);



回答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.



来源:https://stackoverflow.com/questions/10701405/how-to-retrieve-a-user-profile-picture-in-liferay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!