Access Users Profile Picture

Hello,

I am trying to get the Profile Picture of a user with username "test". I always get an null Pointer Exceptions. My users a generated from a LDAP, so they are listet within the database table cwd_users.

Can anyone help me getting the profile picture. Or is there any possibility to use the User Profile Macro within an Stringbuilder under Java Macro/Plugin development?

Thx in advance

5 answers

1 accepted

This widget could not be displayed.

By using the DefaultUserAccessor it's possible.

ProfilePictureInfo pic = defaultUserAccessor.getUserProfilePicture(accountName);

String pathToImage = pic.getDownloadPath();

This widget could not be displayed.

Are you trying to create plugin that shows user's profile picture? If you are using Gravatar to host them, you can use e-mail addres and this code:

private String hex(byte[] array) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < array.length; ++i) {
            sb.append(Integer.toHexString((array[i]
                    & 0xFF) | 0x100).substring(1,3));
        }
        return sb.toString();
    }

    private String md5Hex (String message) {
        try {
            MessageDigest md =
                    MessageDigest.getInstance("MD5");
            return hex (md.digest(message.getBytes("CP1252")));
        } catch (NoSuchAlgorithmException e) {
        } catch (UnsupportedEncodingException e) {
        }
        return null;
    }

    private String getAvatarURLByEmail(String sEmail)
    {
        String hash = md5Hex(sEmail);
        return "https://secure.gravatar.com/avatar/"+hash+"?d=mm&s=24";
    }

To get user's email, get User object (or ApplicationUser) and use function .getEmailAddress:

Collection<User> colUsers = UserUtils.getAllUsers();
for (User user: colUsers)
{
    // print this: user.getEmailAddress();
}

This widget could not be displayed.

Tanks, but I don't use Gravatar.

How do I get a User? I have the username but I don't know how to get the user from Confluence

This widget could not be displayed.

further answers?

This widget could not be displayed.

How do we instantiate an instance of DefaultUserAccessor? I'm having trouble figuring out what to pass to the the constructor of DefaultUserAccessor.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published 9 hours ago in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

38 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you