Search code examples
azure-active-directorymicrosoft-graph-apionedriveazure-ad-graph-api

Upload files to One Drive using Graph API


I am trying to upload a small word document to a folder in my One Drive using Graph API. I am using this endpoint to create the upload session.

POST /users/{userId}/drive/items/{itemId}/createUploadSession

It is giving me the following error:

{
  "error": {
    "code": "nameAlreadyExists",
    "message": "Cannot create an upload session on a folder",
    "innerError": {
      "date": "2020-09-22T09:52:51",
      "request-id": "********",
      "client-request-id": "********"
    }
  }
}

what am I doing wrong?


Solution

  • You cannot work on a folder, but on a file.

    POST /users/{userId}/drive/items/{folderId}:/{fileNameUploadFile}:/createUploadSession