0

I've been trying to write an app that uploads files to a OneDrive for Business account through the Files REST API.

I've successfully been able to use do this by using with the following method

  1. Creating an empty file in the root directory.
  2. Uploading the file contents in a second API call.
  3. Updating the file properties to move it to the correct subdirectory in a third API call.

However, according to the documentation (https://msdn.microsoft.com/office/office365/APi/files-rest-operations#FileoperationsUploadcontentforafileREST) I should be able to do this in a single API call.

Unfortunately that endpoint's documentation isn't clear on what the payload should be and doesn't have any examples (haven't found any online either).

I've been taking guesses on the headers/formats, but they look similar to

POST https://{tentant}-my.sharepoint.com/_api/v1.0/me/files/{parent-id}/children/add
Content-Type: multipart/related; boundary=my_boundary

--my_boundary
Content-Type: application/json

{ path : 'my_doc.txt', nameConflict : 'abort', type : 'File' }
--my_boundary
Content-Type: application/octet-stream

{file stream}
--my_boundary--

Every combination I've tried so far returns this error:

  {
    "code"=>"InvalidArgument",
    "message"=>"The argument is invalid, missing, or has an incorrect format"
  }

Where am I going wrong?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • Reviewing your question, do you really need multipart uploads for your scenario or do you just need the larger file support? – Peter Nied Aug 24 '16 at 18:49

1 Answers1

0

The OneDrive for Business files api is still growing, at this time Multi-part uploads are not yet supported.

Looking at the documentation for the older file v1 api (from this link), when it talks about multi-part, it is talking about combining multiple requests of the same type, e.g. uploading 3 files in a single payload, not uploading a file and updating its metadata in a single request.

To get the most up to date information about the OneDrive Apis watch https://dev.onedrive.com or follow https://twitter.com/OneDriveDev

Peter Nied
  • 1,820
  • 1
  • 13
  • 22
  • Any updates on when you'll support uploads larger > 4mb? It's been nearly a year since OneDrive team said it's in the backlog. – Corey Rowell Aug 24 '16 at 18:13
  • Thanks for pinging this question, resumable upload with fragments is available in ODB which will allow for files larger than 4mb to be uploaded, but multipart (metadata+payload) is not supported. See https://dev.onedrive.com/items/upload_large_files.htm for details, and I'll post a new answer – Peter Nied Aug 24 '16 at 18:18