I struggling to upload an image to SharePoint online using Graph API from within Graph Explorer. I have managed to upload text file which uploads correctly but when attempting image its corrupted.

I am pushing image Base64 in body and it will create image to SharePoint online but corrupted/unable to open. I also tried to include header Content-Type image/png

Upload snippet from Graph Explorer

Image in SharePoint:

Image view in SharePoint

Any help will be appreciated!

1

There are 1 best solutions below

0
RaytheonXie-MSFT On

You need to convert from base64 to binary:

Convert.FromBase64String(base64Image);    
request.AddHeader("Content-Type", "application/octet-stream");
request.AddHeader("Content-Length", binaryImage.Length);
request.AddParameter("application/octet-stream", binaryImage, 
ParameterType.RequestBody);