I'm trying to upload file to a OneDrive from my Java application, but i dont understand the flow and dont see any documentation or methods within SKD for file upload.
The only flow i've found is:
driveClient.me().drive().root().createUploadSession(uploadProperties).buildRequest().post()
But this results in NPE: source
.
how can i set the content as InputStream ?
You must use the ChunkedUploadProvider. Here is the official sample code for uploading large files: https://docs.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=java
For me this sample worked for files with size less than 1.9921875 GB. Unfortunately larger files failed with "Upload session failed too many times" error. The solution is to get the file size using File.length() method:
instead of
as it is shown in the sample.
This happens because fileStream.available() returns the available bytes as integer and integer's max value in bytes is ~2GB.
I hope this helps you.