Skip to content

Commit

Permalink
Fix: file size not match while uploading office docs to SharePoint sites
Browse files Browse the repository at this point in the history
  • Loading branch information
HFO4 committed Mar 21, 2021
1 parent 144b534 commit 6efd8e8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion service/callback/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,15 @@ func (service *OneDriveCallback) PreProcess(c *gin.Context) serializer.Response

// 验证与回调会话中是否一致
actualPath := strings.TrimPrefix(callbackSession.SavePath, "/")
if callbackSession.Size != info.Size || info.GetSourcePath() != actualPath {
isSizeCheckFailed := callbackSession.Size != info.Size

// SharePoint 会对 Office 文档增加 meta data 导致文件大小不一致,这里增加 10 KB 宽容
// See: https://github.com/OneDrive/onedrive-api-docs/issues/935
if strings.Contains(fs.Policy.OptionsSerialized.OdDriver, "sharepoint.com") && isSizeCheckFailed && (info.Size > callbackSession.Size) && (info.Size-callbackSession.Size <= 10240) {
isSizeCheckFailed = false
}

if isSizeCheckFailed || info.GetSourcePath() != actualPath {
fs.Handler.(onedrive.Driver).Client.Delete(context.Background(), []string{info.GetSourcePath()})
return serializer.Err(serializer.CodeUploadFailed, "文件信息不一致", err)
}
Expand Down

0 comments on commit 6efd8e8

Please sign in to comment.