问题
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);
回答1:
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"/>
回答2:
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 }}"
来源:https://stackoverflow.com/questions/49108644/handling-photo-response-from-microsoft-graph