Graph API One Drive Upload Image from URL

Nicholas Roeder 26 Reputation points
2022-09-18T17:26:27.263+00:00

I'm trying to upload an image from a URL but cannot get it to work, the file is created but has no data. I've looked through all documents and cannot seem to find the issue. User account E3 license.

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office OneDrive For business Windows
Microsoft Security Microsoft Graph
{count} vote

Accepted answer
  1. Srinivasa Rao Darna 6,761 Reputation points Microsoft External Staff
    2022-09-19T15:45:06.44+00:00

    Hi @Nicholas Roeder ,

    You can upload files to OneDrive, and the contents of the request body should be the binary stream of the file to be uploaded.
    With following example, I am able to upload a image file.

    PUT /me/drive/root:/FolderA/FileB.png:/content  
    Content-Type: image/png  
      
    The contents of the file goes here.  
    

    Here is the result of my test,
    242555-sample.png

    Reference: driveitem-put-content.

    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.