microsoftgraph / microsoftgraph/msgraph-sdk-java
File Corruption in SharePoint Upload via Microsoft Graph API
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 444
- Forks
- 154
- Avg merge
- 18h 28m
- Merged PRs (30d)
- 4
Description
Describe the bug
I am using the Microsoft Graph API 5.80.0 to upload files to SharePoint from a Java Spring Boot application. The upload works fine in normal conditions, but some files become corrupted while uploading & so unable to download from SharePoint.
Most of the upload files are smaller than 4 MB, so I am using the simple upload method (PUT request).
The upload process completes successfully (returns 200 OK with a valid file ID). When I receive the webhook for the same the file size is 0 & not able to open the file as the file is corrupted. It happens randomly for a few of the requests.
private fun uploadFile(document: DocumentUploadStream) {
val timeMillis = System.currentTimeMillis()
val buildDriveItemRequest : DriveItemRequestBuilder = microsoftGraphClient.drives("driveId").root().itemWithPath(document.path)
if (document.size < 4 * 1024 * 1024) {
// Simple upload for small files
val driveItem = retry {
refreshToken {
buildDriveItemRequest.content().buildRequest()
.put(document.contentToStream.readAllBytes())
}
}
logger.info { "Upload done ${document.path}, id: ${driveItem?.id}, time: ${(System.currentTimeMillis() - timeMillis)/1000}s" }
document.id = driveItem?.id
} else {
// Large files use upload sessions (this part is working fine)
}
}
data class DocumentUploadStream(
val path: DocumentPath,
val contentToStream: InputStream,
val size: Long
)
Expected behavior
The file should not get corrupted on upload.
Any insights or recommendations would be greatly appreciated!
Thanks
How to reproduce
With the attached snippet of code, it should be reproducible randomly.
SDK Version
5.80.0
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
_No response_
### Other information
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the simple-upload branch in the provided uploadFile snippet and review how document.contentToStream is consumed by the Microsoft Graph SDK 5.80.0 call. Reproduce the intermittent case while comparing the source size, uploaded SharePoint size, and webhook timing; done means identifying a reliable cause and a verified correction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin, spring-boot
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100