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
- Creating an empty file in the root directory.
- Uploading the file contents in a second API call.
- 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?