Search code examples
microsoft-graph-apimp4onedrivebad-request

The graph api is throwing BadRequest while writing mp4 file


I am trying to write a video file chunk by chunk at onedrive but, the graph api throws me a BadRequest.

Can anyone help me out...

I am using this code to write the files, other than video file I am able to create and write the file at onedrive.

graphClient.Users[UserEmailID].Drive.Items[Item.ParentItemID].Children.Request().AddAsync(SourceDriveItem).Result;

Following is the Json of SourceDriveItem

    {
  "file": {
    "hashes": {
      "quickXorHash": "bxXAIfX9S1d5xN8dqthmIc0m5L8=",
      "@odata.type": "microsoft.graph.hashes"
    },
    "mimeType": "video/mp4",
    "@odata.type": "microsoft.graph.file"
  },
  "fileSystemInfo": {
    "createdDateTime": "2021-08-20T07:38:52+00:00",
    "lastModifiedDateTime": "2021-08-20T07:38:52+00:00",
    "@odata.type": "microsoft.graph.fileSystemInfo"
  },
  "photo": {
    "takenDateTime": "2015-08-07T09:13:02+00:00",
    "@odata.type": "microsoft.graph.photo"
  },
  "size": 1570024,
  "video": {
    "audioBitsPerSample": 110288,
    "audioChannels": 2,
    "audioFormat": "{00001610-0000-0010-8000-00AA00389B71}",
    "audioSamplesPerSecond": 48000,
    "bitrate": 291808,
    "duration": 30526,
    "fourCC": "H264",
    "frameRate": 30000.0,
    "height": 270,
    "width": 480,
    "@odata.type": "microsoft.graph.video"
  },
  "createdDateTime": "2021-08-20T07:38:52+00:00",
  "lastModifiedBy": {
    "user": {
      "displayName": "SysTools Dev2",
      "id": "38a682a6-5390-4e43-8610-442f35cb0026",
      "@odata.type": "microsoft.graph.identity",
      "email": "admin@dev2systoolsgroup.onmicrosoft.com"
    },
    "@odata.type": "microsoft.graph.identitySet"
  },
  "lastModifiedDateTime": "2021-08-20T07:38:52+00:00",
  "name": "file_example_MP4_480_1_5MG.mp4",
  "@odata.type": "microsoft.graph.driveItem"
}

Solution

  • I just set null to the Video property in the request body and it get solved. So avoid setting the Video object in DriveItem while adding the file