Try our conversational search powered by Generative AI!

Exposing the full URL of the Portrait image

Vote:
 

I'm working on an integration with another web site and in doing so need to expose the absolute HTTP URL to a user's portrait image. So far I have found out how I can get at user's EPiServer.Community.ImageGallery.Image object (if the user has a profile image, else it's null) by calling:

Image portrait = MyPageHandler.Instance.GetMyPage(CurrentUser).Portrait;

This returns the correct Image object. However, getting a URL to it is proving to be somewhat arkward. The property 'Image.AbsolutePath' is returning
something that looks similar to the physical directory path, but not quite. From what I can see it looks like the returned filename is being appended with the author's ID inserterd after the orignal filename, but before the file type extension, or so it seems...

So is there any simple way to get a URL to the portrait image?

Regards

Lee Francis

 

#53510
Sep 12, 2011 15:04
Vote:
 

Hi Lee,

Using your Image object as described above, your can get the url by calling ImageGalleryHandler.Instance.GetThumbnail(...) like this:

if (portrait != null)
{
  var thumb = ImageGalleryHandler.Instance.GetThumbnail(portrait, portrait.Width, portrait.Height, ThumbnailFormat.Exact);
  if (thumb != null)
     string imageUrl = new UrlBuilder(thumb.Url).Uri;
}

    

You should take a close look at the GetThumbnail method as it has several overloads, and you might want to use a difference one than the one I've used in this example. In this piece of code, I've retrieved the image in it's original size, you can also choose to retrieve it in a different size (for instance as a thumbnail).

Also, if profile images need to be approved, you should add a check to see if the image has been approved before exposing it :)

Hope this helps!

Karoline

#53513
Sep 13, 2011 8:32
Vote:
 

Thank you so much, Karoline! Great answer!

This is just what I needed to get me started in the right direction. :-)

#53522
Sep 13, 2011 13:51
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.