How can I upload a file to a personal OneDrive account?
还没有人认领这个 Issue。
评估
调研方向
从链接的 upload-file-to-onedrive 示例和使用 Drives().ByDriveId().Items().ByDriveItemId().Children().Post 的 Go 调用开始。重现个人账户和 Microsoft 365 账户的两个已报告错误,然后确定 SDK 是否支持此上传流程。支持的行为或所需的 workflow 得到记录并验证后,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Hi, I'm working on a service that will automatically upload files that a user has requested periodically to their OneDrive. While I've managed to get this working for users with a Microsoft 365 account, I haven't been able to successfully upload a file for users with a personal Microsoft account / to their personal OneDrive.
Does the this SDK support uploading files to a personal OneDrive, and if so how would I do that?
A short example of what I have working for a Microsoft 365 account is in this repository - https://github.com/chriswilding/upload-file-to-onedrive.
The same technique does not work for a personal OneDrive. With a Microsoft 365 OneDrive account I was only able to upload a file in a two step process, first PUTing the file, and the POSTing the content. With a personal OneDrive account both setting and not setting the content results in an error.
name := "example.txt"
contentType := "text/csv"
data := []byte("Hello,World!")
newFile := models.NewFile()
newFile.SetMimeType(&contentType)
fileItem := models.NewDriveItem()
fileItem.SetName(&name)
fileItem.SetAdditionalData(map[string]interface{}{
"@microsoft.graph.conflictBehavior": "replace",
})
fileItem.SetFile(newFile)
// When trying to upload to a personal OneDrive account, if the content is set the a error is returned -
// Error creating file item: [child] A stream property 'content' has a value in the payload. In OData, stream property must not have a value, it must only use property annotations.
// error: invalidRequest
// error: [child] A stream property 'content' has a value in the payload. In OData, stream property must not have a value, it must only use property annotations.
//
// However, if the content is not set then a different error is returned -
// Error creating file item: Cannot create a file without content
// error: invalidRequest
// error: Cannot create a file without content
// fileItem.SetContent(data)
createdFileItem, err := client.Drives().ByDriveId("aDriveID").Items().
ByDriveItemId("aParentDriveItem").Children().
Post(context.Background(), fileItem, nil)
- 主要语言
- Go
- 星标
- 335
- 派生
- 43
- 平均合并
- 15 小时 19 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoftgraph/msgraph-sdk-go 的其他 Issue
-
ItemItemsItemPermanentDeleteRequestBuilderInternal.Post missing content body/content-type headers未关闭status:waiting-for-triage type:bug
难度 3/5 1-2 天 新手友好度 48/100
microsoftgraph/msgraph-sdk-go#980 ·
-
status:waiting-for-triage type:bug
难度 4/5 3-5 天 新手友好度 35/100
microsoftgraph/msgraph-sdk-go#972 ·
-
status:waiting-for-triage type:bug
难度 3/5 1-2 天 新手友好度 45/100
microsoftgraph/msgraph-sdk-go#969 · 1 条评论 ·
-
status:waiting-for-triage type:feature
难度 3/5 1-2 天 新手友好度 45/100
microsoftgraph/msgraph-sdk-go#964 ·
-
status:waiting-for-triage type:feature
难度 5/5 一周以上 新手友好度 20/100
microsoftgraph/msgraph-sdk-go#940 · 1 条评论 ·
查看 microsoftgraph/msgraph-sdk-go 的全部 Issue
相似的 Issue
-
agent-butler-finding chore
难度 1/5 1 小时以内 新手友好度 88/100
jordansmall/spindrift#4146 ·
维护者通常 1 天内回复
-
security
难度 2/5 1-3 小时 新手友好度 68/100
IBM/ibmcloud-volume-file-vpc#119 ·
-
security
难度 2/5 1-3 小时 新手友好度 66/100
IBM/networking-go-sdk#339 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
kubernetes-sigs/mcp-lifecycle-operator#439 ·
维护者通常 1 天内回复
-
area: global bug dx priority: low
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复