How do you upload a .doc/.docx file to drive through the Graph API?

Erica 1 Reputation point
2021-03-06T00:20:09.83+00:00

I am looking at this documentation to upload files to drive through the Graph API: https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http

How would you upload a .doc or .docx file? What would the headers/params/body need to look like?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,714 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Danstan Onyango 3,741 Reputation points Microsoft Employee
    2021-03-09T08:04:43.043+00:00

    Let me first point out that if you are uploading a file larger than 4MB, you need to use Upload large files with an upload session.. That said, the documentation you have mentioned says how uploading a file and for .docx file, Here is a curl sample that you can use with all headers and body well defined.

    curl --location --request PUT 'https://graph.microsoft.com/v1.0/me/drive/root:/MyWordDoc.docx:/content' \  
    --header 'Content-Type: text/plain' \  
    --header 'Authorization: Bearer eyJ0eXAiOiJKV1...' \  
    --data-binary '@/C:/Path/File/Document.docx'  
    

    You may also find this guide on Upload large files using the Microsoft Graph SDKs helpful.

    0 comments No comments