question

beschickAT avatar image
0 Votes"
beschickAT asked beschickAT edited

MS Graph: /me/photo/$value --> returning application/octet-stream MIME type

About:
My solution (a middle tier api) is accessing the MS graph endpoint https://graph.microsoft.com/beta/me/photos/$value with an on-behalf-of access token.

Reuquest headers:
headers: {
'Authorization': Bearer ...,
'content-type': 'image/jpg'
}

As per documentation the endpoint is returning binary data which need to be converted to a base64 string for - example - return to the client to later on display the image in the browser.

Problem:
When I convert the binary to a base64 string and then would like to decode, I get the information that it is an invalid mime type: application/octet-stream.
Is this the MIME type by design? How can I transform that into a "valid" mime type?



If I fetch the meta data, it the payload is the following:

{
"@odata.mediaContentType": "image/pjpeg",
"@odata.mediaEtag": "",
"id": "200X300",
"height": 300,
"width": 200
}



azure-ad-graph
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

beschickAT avatar image
0 Votes"
beschickAT answered beschickAT edited

OK, got the answer myself.
I am used to use Axios library for the requests; There was one configuration property in the request missing, the response type must be "arraybuffer" (not "stream", not "blob").

So, the request properties are then something like that:

   {
         headers: {
             'Authorization': `Bearer ....`,
             'content-type': 'image/jpeg'
         },
         responseType: 'arraybuffer'
     });

After enconding that as base64 string, the decoding back to .jpeg also works fine!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.