Search code examples
liferayprofileimageliferay-6

How to retrieve a user profile picture in Liferay


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?


Solution

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