I used the application permission flow for autentication, with API persmissions User.ReadWrite.All
I want to update/synchronize profile images from our users with images that are stored in a seperate database.
For debugging purpose i retrieve the image from the datebase in a "old-skool" windows-forms picture box. The image will then be transmitted to office 365 with the following code:
Dim pic = New MemoryStream
PictureBox1.Image.Save(pic, Imaging.ImageFormat.Jpeg)
Dim Photo = Await graphServiceClient.Users(TxtEmail.Text).Photo.Content.Request().PutAsync(pic)
This raises an exeception:
Microsoft.Graph.ServiceException
HResult=0x80131500
Message=Code: ErrorItemNotFound
Message: The specified object was not found in the store., No photo with class 'IPM.UserPhoto.Preview' exists.
Inner error
Source=Microsoft.Graph.Core
StackTrace:
at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__34.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendStreamRequestAsync>d__32.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Firebird_Test_Photo.Form1.VB$StateMachine_5_BtnUpdateExchanhe_Click.MoveNext() in C:\Users\jodur.KREMER\source\repos\Firebird Test Photo\Firebird Test Photo\Form1.vb:line 125
A simular code below for retrieving the image into a picturebox works fine
Dim Photo = Await graphServiceClient.Users(TxtEmail.Text).Photo.Content.Request().GetAsync()
PictureBox2.Image = System.Drawing.Image.FromStream(Photo)
The update of the photo with the stream as i retrieved with this function also results in the same exception, so i don't suspect an invalid stream.
Any suggestions for this problem?? Suggetions in C# are also welcom!
$httpClient = [System.Net.Http.HttpClient]::new()
$httpClient.DefaultRequestHeaders.Authorization = [String]::Format('Bearer {0}', $accessToken)
$uri = [System.Uri]::new("https://graph.microsoft.com/v1.0/users/$($AzUserUPN)/photo/$value")
# Prepare Content
$content = [System.Net.Http.ByteArrayContent]::new([System.IO.File]::ReadAllBytes($AzUserImage));
$content.Headers.ContentType = "image/jpeg";
$task = $httpClient.PutAsync($uri,$content)
$task.Wait()
User contributions licensed under CC BY-SA 3.0