microsoftgraph / microsoftgraph/msgraph-sdk-java

File Corruption in SharePoint Upload via Microsoft Graph API

未关闭
#2,339 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

status:waiting-for-triage type:bug
主要语言
Java
星标
444
派生
154
平均合并
18 小时 28 分钟
30 天内合并 PR
4

描述

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_

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 uploadFile 代码片段中的 simple-upload 分支开始,检查 Microsoft Graph SDK 5.80.0 调用如何使用 document.contentToStream。在比较源大小、上传后的 SharePoint 大小和 webhook 时序的同时,重现该间歇性情况;完成的标准是找出可靠的原因并验证修正方案。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, kotlin, spring-boot
领域
api, backend, cloud
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。