From 82ac9522c82628fcb557f313b4a62a56c13de6f2 Mon Sep 17 00:00:00 2001 From: damienbod Date: Sat, 2 Dec 2023 12:11:04 +0100 Subject: [PATCH] fix stream for photos --- .../Services/GraphApiClientService.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/AngularMicrosoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs b/AngularMicrosoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs index 2e1deb5..dbba04f 100644 --- a/AngularMicrosoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs +++ b/AngularMicrosoftEntraIDMultipleApis/ApiWithMutlipleApis/Services/GraphApiClientService.cs @@ -28,14 +28,13 @@ public async Task GetGraphApiProfilePhoto(string oid) var photo = string.Empty; byte[] photoByte; - using (var photoStream = await _graphServiceClient.Users[oid] - .Photo - .Content - .GetAsync(b => b.Options.WithScopes("User.ReadBasic.All", "user.read"))) + var streamPhoto = new MemoryStream(); + using (var photoStream = await _graphServiceClient.Users[oid].Photo + .Content.GetAsync()) { - photoByte = ((MemoryStream)photoStream!).ToArray(); + photoStream!.CopyTo(streamPhoto); + photoByte = streamPhoto!.ToArray(); } - using var imageFromFile = new MagickImage(photoByte); // Sets the output format to jpeg imageFromFile.Format = MagickFormat.Jpeg;