Search code examples
c#microsoft-graph-apionedrivemicrosoft-graph-files

"DeferCommit was set to false for this upload session" Error


I am trying to implement Upload large files with an upload session.

For now I have (getting the upload session):

UploadSession uploadSession = await graphClient
    .Users["user3@myComp.onmicrosoft.com"]
    .Drive
    .Root
    .ItemWithPath(@"\someFolder\file.txt")
    .CreateUploadSession()
    .Request()
    .PostAsync();

The response from this request is some session URL but when I upload the file chunk to this URL I'm getting an error:

{
  "error": {
    "code": "invalidRequest",
    "message": "DeferCommit was set to false for this upload session."
  }
}

Does anyone know what causes this error?


Solution

  • Without seeing how the request to upload the bytes was made I'm left to guess a little - but I believe the issue is that you used a POST instead of a PUT. The session URL returned needs to have PUT requests made to it, with appropriate Content-Range headers, in order to upload and commit the data.