How to get user profile picture in Liferay

I want to get a user profile picture. How can I do it? Could you share a piece of code? Im using Liferay 6.0.6. It has only user.getPortraitId () and not user.getPortraitURL (). So, as soon as I get the portrait identifier in the JAVA class, what should I do with it?

+4
source share
2 answers

See implementation of UserConstants.getPortraitURL(...) https://github.com/liferay/liferay-portal/blob/master/portal-service/src/com/liferay/portal/model/UserConstants.java

In this approach, you can get the URL of the image.

If you need an image object, you can load it using ImageLocalServiceUtil :

  long portraitId = user.getPortraitId(); Image image = ImageLocalServiceUtil.getImage(portraitId); 
+3
source

There are at least two options for 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 an additional security aspect based on a security market that you may or may not find to suit your needs.

+1
source

Source: https://habr.com/ru/post/1413736/


All Articles