2

I have created API to expose the User Details to an external system in which I am sending all the details regarding users like Name, Email, Language etc. Now I want to send the Profile Photo also, I know we can query and get SmallPhotoUrl and FullPhotoUrl but I don't want URL. I want the actual image in Base64 format.

Any Ideas for this?

5
  • If you have an apex service, would you want to make a rest callout to salesforce API to return the blob of photo URL?
    – Raul
    Commented Mar 20, 2018 at 10:13
  • @RahulSharma Sorry I didn't get you. What I need to do is I want to give the profile photo in a base64 format so they can directly convert it and use it
    – Nirav Shah
    Commented Mar 20, 2018 at 10:20
  • 1
    What is your API, an apex class with restful service?
    – Raul
    Commented Mar 20, 2018 at 10:24
  • yes it is.... @HttpGet
    – Nirav Shah
    Commented Mar 20, 2018 at 10:29
  • I have created the class with restful service HttpGet
    – Nirav Shah
    Commented Mar 20, 2018 at 10:34

1 Answer 1

4

Here's an easy 4 step snippet to get a profile photo as a base64 image:

// 1. Query for user info 
User u = [Select SmallPhotoUrl, FullPhotoUrl From User where id = :Userinfo.getUserid()];

// 2. "Navigate" to the page with the image 
PageReference ref = new PageReference(u.FullPhotoUrl); 

// 3. Get the content of that page (the image) as a blob
Blob b = ref.getContent();

// 4. Convert it to base64   
String base64 = EncodingUtil.base64Encode(b); 

System.debug(base64);

Currently working on something very close to this, will update this post with any findings.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .