I have a service that allows me to change a user's profile picture.

The petition type is POST, and it has the following structure:

   "PhotoUrl":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD[...]" //shortened

What I'm trying to do is update my users profile picture with this (entry is the object storing request properties):

 document = new Document();
 document.Type = 'jpg'; 
 document.IsPublic = true;
 document.AuthorId = entry.UserId;
 document.FolderId = entry.UserId;
 document.Name = 'New Profile picture';
 document.Body = EncodingUtil.base64Decode(entry.PhotoUrl);
 insert document;

 //Update user profile picture
 ConnectApi.Photo photo = ConnectApi.UserProfiles.setPhoto(null, entry.UserId, new ConnectApi.BinaryInput(document.Body, 'image/jpg', 'newprofile.jpg'));

And it's giving me the following error:

Unrecognized base64 character: :

Does anyone know how can I solve this?


1 Answer 1


Can you try validating your base64 photo URL at https://base64.guru/tools/validator. maybe there is some issue with URl or undefined value.

Sometimes you need to deserialize the JSON first, into a String, and then Base64-decode that String.

  • 1
    Thanks! It was due to the url.
    – molinet
    Mar 11, 2021 at 9:07

This site is temporarily in read-only mode and not accepting new answers.

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