Total Pageviews

Tuesday, May 22, 2012

Getting User Image


Following are two code snippets which can be used for getting user image:

and
Hope this will help.

5 comments:

  1. Thanks a lot Apoorva for this post.
    But here is my predicament:
    I retrieve a user from Liferay DB, based on his screenName or emailID. Then i retrieve all the users that belong to the group that this user belongs to. So when i retrieve those users (lets call them his buddies), I wanna be able to retrieve their profile pictures as well. All this, i do in the java class. So will i have to pass on eash user object to the jsp files containing above snippets and then retrieve the image object in the jsp? Or could there be a straight forward way.

    Thanks a lot once again :)

    ReplyDelete
    Replies
    1. Praveen,

      In java, you get change as following:

      String path = user.isFemale()? "female" : "male" + "_portrait?img_id=" + Long.valueOf(user.getPortraitId()) + "&t=" + Long.valueOf(ImageServletTokenUtil.getToken (user.getPortraitId()));

      you can use this code in conjuction with themeDisplay on JSp.

      Hope this will help.

      Delete
    2. Thanks Apoorva...
      But i wanna do this in Java and not inside a jsp.. Is it possible?

      Delete
  2. Apoorva,
    I used the below code to retrieve the user image object and it worked fine for me :)

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

    ReplyDelete