Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

How can I upload a file to a personal OneDrive account?

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

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
go
领域
api, cloud

调研方向

从链接的 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

环境准备

从这里开始

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

microsoftgraph/msgraph-sdk-go 的其他 Issue

查看 microsoftgraph/msgraph-sdk-go 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

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