Error uploading user picuture vai Graph api

24 views Asked by At

I'm trying to upload an image from local drive to Graph via the UploadFile api. Here is my code

string filename = "S:\\28-sept\\leo.jpg";
byte[] bytes = File.ReadAllBytes(filename);   

// GetHttpRequest return HtppRequestMessage with Bearer token set. 
// I confirm graphAccessToken is correctly set                   


 var req =  GetHttpRequest(HttpMethod.Put, "https://graph.microsoft.com/v1.0/users/fe7b8732-ca7b-4cc7-b524-4093fc13dfd3e/photo/$value", logger);
 ByteArrayContent streamContent = new ByteArrayContent(bytes);
 streamContent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
 req.Content = streamContent;
    
 var client = new HttpClient();          
 HttpResponseMessage response = client.SendAsync(req).Result;
 string strResp = response.Content.ReadAsStringAsync().Result;

The error:

{
  "error": {
    "code":"**UnknownError**",
    "message": "",
    "innerError": {
      "date":"2024-01-25T16:42:32",
      "request-id":"{{Some-GUID}}",
      "client-request-id":"{{Some-GUID}}"
    }
  }
}

The application permissions are enter image description here.

Any idea what's going on? Do I have to grant User.ReadWrite.All Application permissions for this?

0

There are 0 answers