Home > Enterprise >  Upload large file to sharepoint site using Microsoft Graph via REST API
Upload large file to sharepoint site using Microsoft Graph via REST API

Time:05-09

I'm trying to upload a file to a specific sharepoint site. In this page shows me how to upload a sample file to user's onedrive. But, in my case, I need to upload to sharepoint. I'm trying to use this endpoint:

POST /groups/{groupId}/drive/items/{itemId}/createUploadSession

But show me this error response:

{
"error": {
    "code": "itemNotFound",
    "message": "Item not found",
    "innerError": {
        "date": "2022-05-08T23:15:29",
        "request-id": "ca4362ca-ff36-488c-80b1-9f82c3448cd5",
        "client-request-id": "ca4362ca-ff36-488c-80b1-9f82c3448cd5"
    }
}

This is cURL:

curl --request POST \
  --url https://graph.microsoft.com/v1.0/groups/{groupId}/drive/items/test.txt/createUploadSession \
  --header 'Authorization: Bearer xxxx' \
  --header 'Content-Type: application/json' \
  --data '{
  "@microsoft.graph.conflictBehavior": "rename",
  "description": "description",
  "fileSize": 4,
  "name": "test.txt"
}'

CodePudding user response:

You are trying to call endpoint which requires itemId but you send file name instead of itemId.

POST /groups/{groupId}/drive/items/{itemId}/createUploadSession

Another way is to specify the path to the file. The item-path must contain the name of the item that's specified in the request body.

POST /groups/{groupId}/drive/root:/{item-path}:/createUploadSession
// file system path using /drive/root:/path/to/file
POST /groups/{groupId}/drive/root:/path/to/test.txt:/createUploadSession
  • Related