none
User Profile images not appearing RRS feed

  • Question

  • I created a web part to show user profile images, and having difficulty getting them to consistently show up. Well, most of the time they don't. Below is the simplest example, using regular old HTML (Yes, I've authenticated against the sharepoint site).

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> </head> <body> <img src="https://alias-my.sharepoint.com:443/User%20Photos/Profile%20Pictures/neilar_alias_onmicrosoft_com_LThumb.jpg" /> </body> </html>

    When open the HTML in a (authenticated) browser, the image does not appear most of the time. Like, it rarely shows up, refreshing or closing/re-opening the page doesn't help. But - if I paste the src value of my <img> directly into a new tab on the browser, the image shows up just fine! Subsequently, if I bring up the html page again, or refresh it, the image suddenly appears.

    Is there some trick to getting User Profile images to show up? The HTML I'm using above is isolating the issue as narrowly as I can, the actual webpart is using the ms-persona styles to show users and details about those users. (name, title, etc.)


    who will babysit the babysitters?

    Thursday, January 12, 2017 6:13 PM

Answers

  • Lee, you're absolutely correct. I (finally) looked at the page in Fiddler and am getting 302's back from all the image url's. Grumble! I understand why it's happening, and it took me a while to find what I think is the correct solution. Though I'm not a fan of having a hardcoded '15' in the path, and have done minimal testing, but this appears to work rather than using the url provided by user.get_PictureUrl()

    hostWeb.get_url() + "/_layouts/15/userphoto.aspx?size=L&accountname=" + encodeURIComponent(user.get_email())
    

    When I run the web part in a proper hosted page, it works as expected. Fiddler still give me a 302, but the redirect is handled automagically.


    who will babysit the babysitters?

    Tuesday, January 24, 2017 2:28 AM

All replies

  • Here you go

    https://collab365.community/sharepoint-2010-dispaly-a-users-profile-picture-in-a-content/

    http://www.glynblogs.com/2010/11/display-a-users-picture-in-the-content-query-web-part.html


    Please remember to click Mark as Answer on the answer if it helps you

    Thursday, January 12, 2017 8:28 PM
  • Thanks. I'm getting my information (list of users) from a SP Group, and currently using (javascript) CSOM to feed the HTML bits, perhaps that's not the correct SP way? (I'm using o365 SharePoint) I'll play with the content query web part to see if I can make it work the same. I'm using the ms-personal style so it looks like this:


    who will babysit the babysitters?

    Thursday, January 12, 2017 10:00 PM
  • Taking a small step back, does anyone know *why* the images aren't appearing with simple HTML? Yea, I'll look at using the content query web part, though I'm not convinced in my case it will work. (I haven't found where I can query all the users from a SP group, it appears to only work with site content and lists.)

    who will babysit the babysitters?

    Friday, January 13, 2017 4:46 PM
  • Hi,

     

    You could get user profile image by REST api, for example:

    https://xxx.sharepoint.com/sites/dev/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='PictureURL')?@v='i:0%23.f|membership|user@xxx.onmicrosoft.com'

     

    You could call the rest api by Ajax, you could check below link for more details.

    http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, January 18, 2017 8:28 AM
  • Hey Lee,

    I'm not sure why I'd want to do this, since would result in one REST call for every single user. I'm using CSOM so I can easily wrap the query for all users in a SP group to a single transaction, rather than one per user. (Imagine the performance where I have 30+ users!)

    Again, I think my core question is why referencing the URL provided by PeopleManager.get_pictureUrl() doesn't result in the picture appearing. Even when I try to add the image on a SharePoint page by the same URL, it is not appearing. (Using Page->Edit->Insert->Picture)


    who will babysit the babysitters?


    Wednesday, January 18, 2017 3:28 PM
  • Hi,

     

    Seems you’re trying to access online user profile image in different domain, this action need authentication information.

    You could use fiddler tool to monitor the requests and check the requests flow.

    For example, if you authenticated with early requests and then request the  image, the server will response the image, however, if you haven’t authentication information yet, you’ll be redirect to login server but this can’t be display in cross domain html.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, January 19, 2017 7:43 AM
  • I don't believe this is a cross-domain issue. Sometimes, but not often, or reliably, an occasional profile picture will magically start appearing.

    I've worked with cross-domain issues, requests were flatly rejected until I resolved the problem.


    who will babysit the babysitters?

    Thursday, January 19, 2017 2:21 PM
  • Here's an example, where one of the profile pictures suddenly starts appearing, and others do not. It's the same markup and javascript CSOM doing the work, the user profiles have been around for at least a week and were created within an hour of each other. In this particular case I'm using Firefox, which tends to show the pictures more often than IE/Edge.


    who will babysit the babysitters?

    Thursday, January 19, 2017 4:46 PM
  • Lee, you're absolutely correct. I (finally) looked at the page in Fiddler and am getting 302's back from all the image url's. Grumble! I understand why it's happening, and it took me a while to find what I think is the correct solution. Though I'm not a fan of having a hardcoded '15' in the path, and have done minimal testing, but this appears to work rather than using the url provided by user.get_PictureUrl()

    hostWeb.get_url() + "/_layouts/15/userphoto.aspx?size=L&accountname=" + encodeURIComponent(user.get_email())
    

    When I run the web part in a proper hosted page, it works as expected. Fiddler still give me a 302, but the redirect is handled automagically.


    who will babysit the babysitters?

    Tuesday, January 24, 2017 2:28 AM