0

I can't figure out what actually is returned by this call and how I can display it in HTML as an img tag. When I use the same URI using the online Microsoft Graph Explorer test environment I get the image as intended.

var requestUri =
    "https://graph.microsoft.com/v1.0/barfoo.onmicrosoft.com/users/xxxxx-xxxxxx-xxxxx/photo/$value";

var request =
    new HttpRequestMessage(HttpMethod.Get, requestUri);

var accessToken =
    await _authenticationHelper.GetAccessTokenAsync();

request.Headers.Authorization =
    new AuthenticationHeaderValue("Bearer", accessToken);

var response = await client.SendAsync(request);
Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
Daarwin
  • 2,896
  • 7
  • 39
  • 69

2 Answers2

2

HttpClient can give you the response as a Stream.

In ASP.NET Core, I've done this with:

[HttpGet]
public async Task<IActionResult> ProfilePhoto()
{
    //removed all the code which you already have
    HttpResponseMessage res = await client.SendAsync(request);

    return File(await res.Content.ReadAsStreamAsync(), "image/jpeg");
}

"Classic" ASP.NET MVC should be pretty identical, you would replace IActionResult with ActionResult at least.

You can then link this to an image tag like:

<img src="/Home/ProfilePhoto"/>
juunas
  • 54,244
  • 13
  • 113
  • 149
-1

Once you have the users photo response you should be able to render the image along the following lines: src="data:image/jpeg;base64,{{ user.profilePic }}"

  • I think i have trouble before this. SendAsync(request) returns a HttpResponseMessage correct? How do i get a photo or blog from that? – Daarwin Mar 05 '18 at 12:32