Search code examples
office365office365apimicrosoft-graph-apioffice365-restapi

Uploading User Profile Photo on office 365 graph api by base64 string


Basically what Im trying to do is this

https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/profilephoto_update

I need to mass update all the profile photos

Ive already have the server endpoint application setup with correct permissions.

the problem is that i do not have the file itself but just base64 string value of the file.

is there a possible way to update the profile pictures with just the value?


Solution

  • As per the documentation you've already referenced (https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/profilephoto_update) the Microsoft Graph only accepts profile picture images as bytes.

    You can easily convert your base64 string value to bytes using the following snippet.

    byte[] bytes = Convert.FromBase64String("R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==");