There are two methods to upload a file vis the Microsoft Graph:
The PUT request accepts files up to 4MB in size; all others need to be run via creating an upload session and sending up the file in chunks or as a whole to a URL returned after creating the upload session. You are perfectly capable of using the upload session to upload files less than 4MB in size.
Given that a resumable upload works for all file sizes, I can’t see much reason to use the straight PUT request and would opt for a resumable upload to save my files to OneDrive or SharePoint.
When creating an upload session to a SharePoint document library with more than 5000 items (the SharePoint list threshold), and where the file already exists, we would get the following response:
The remote server returned an error: (404) Not Found.
This is obviously confusing, as the file actually does exist. In fact, in the situation where we are uploading to a library past the threshold but the file DOES NOT exist, everything uploads perfectly well.
Note that this happens in the creating of the upload session, not the upload itself; this error occurs before the upload call can be made. You can add the following to the request body, and in fact, you have to if the file already exists; but there is no effect when the threshold has been exceeded.
I wanted to check if the straight put request (i.e. not the resumable upload) would upload and overwrite a file that exists in a library with more than 5000 items, and it does happily. The only error I did encounter was when the file exceeded 4MB:
The remote server returned an error: (413) Request Entity Too Large.
So what is the best way to upload a file to SharePoint using the Microsoft Graph? Unfortunately, it seems that there isn’t a single way to do it. By default, use the resumable upload; but if you are saving to a location that has more than the threshold allows and the file is to be overwritten, use the straight upload method. But then, if that file is over 4MB, you can’t do a thing.
UPDATE: Colin Wood brought to my attention the SharePoint REST API should be able to perform the upload, as the file upload limit is 2GB, but I haven’t yet tested this against uploading to a list of more than 5000 items. I do know however using the SharePoint CSOM libraries does not fail in the above situation.