0

I'm creating a Sharepoint Application (using Shrepoint Framework) and I'm not being able to retrieve the Phto BLOB returned when calling MSGraph "/me/photo/$value" api. I don't know how to convert the BLOB into a Base64 string. I have made many attempts, I'm writing one to explain what I'm trying to accomplish:

this.context.msGraphClientFactory .getClient() .then((client: MSGraphClient): void => { client.api('/me/photo/$value').get((error, response: any, rawResponse?: any) => { const blobUrl = window.URL.createObjectURL(rawResponse.body); document.getElementById("myPhoto").setAttribute("src", blobUrl); }); });

This code fails because creteObjectURL has been deprecated. The MSGraph call works, but I can't process the response. Any suggestions?

1 Answers1

1

createObjectURL accepts blob as its parameter. And you can get blob response like below:

client.api('/me/photo/$value').responseType('blob').

The bloburl will be like:

blob:https://xxxx-app34cc3db2636944a5b0b3abea9a6ae5b9.sharepoint.com/e007d253-f911-4722-86a8-ecdd77864696

Also you can convert blob to base64 via FileReader: Convert blob to base64

Besides, you can also make use of pnpjs to access ms graph, it could directly return blob data: Current User

Best Regards, Baker Kong

Baker_Kong
  • 1,739
  • 1
  • 4
  • 9