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

Bernd Schickerbauer 116 Reputation points
2020-06-11T18:42:55.073+00:00

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
}

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,854 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bernd Schickerbauer 116 Reputation points
    2020-06-11T19:02:51.317+00:00

    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!

    0 comments No comments

0 additional answers

Sort by: Most helpful