可续传 returns 上传区块时未经授权

Resumable upload returns Unauthorized when uploading chunk

今天我遇到了 OneDrive 通过 Microsoft Graph API 的可恢复上传功能的问题,如 here 所述。我有以前有效的集成测试,现在失败了。

我成功调用了 createUploadSession 并得到了一个 uploadUrl 来使用。我在这里用 "XXX" 替换了实际的标记。

POST https://graph.microsoft.com/V1.0/groups/273c2c33-8533-445d-ae65-4b63be296995/drive/root:/c2fa1a83-74f3-444b-9263-c9539ee3eae2.txt:/createUploadSession HTTP/1.1
Authorization: Bearer XXX

{
  "item": {
    "@microsoft.graph.conflictBehaviour": "replace"
  }
}

回复:

{
    "@odata.context": "https://graph.microsoft.com/V1.0/$metadata#microsoft.graph.uploadSession",
    "expirationDateTime": "2017-04-27T11:07:50.5650598Z",
    "nextExpectedRanges": ["0-"],
    "uploadUrl": "https://sageglodbizp.sharepoint.com/sites/SharePointTests/_api/v2.0/drive/items/01LQXPMG56Y2GOVW7725BZO354PWSELRRZ/uploadSession?guid='9d14ed72-e532-442e-94e8-70952b365527'&path='~tmp0B_c2fa1a83-74f3-444b-9263-c9539ee3eae2.txt'&overwrite=True&rename=False&access_token=XXX"
}

所以 uploadUrl 就在那里。然后,我尝试将一个块放入此 url 但得到一个 401 Unauthorized 作为响应:

PUT https://sageglodbizp.sharepoint.com/sites/SharePointTests/_api/v2.0/drive/items/01LQXPMG56Y2GOVW7725BZO354PWSELRRZ/uploadSession?guid='9d14ed72-e532-442e-94e8-70952b365527'&path='~tmp0B_c2fa1a83-74f3-444b-9263-c9539ee3eae2.txt'&overwrite=True&rename=False&access_token=XXX HTTP/1.1
Authorization: Bearer XXX

回应

HTTP/1.1 401 Unauthorized

由于我使用的是图表 API 提供的 URL,我认为这是一个错误。我将与第一次调用相同的承载令牌传递给第二次调用(我也尝试过没有访问令牌,因为它在 URL 中)。

我已经对两个不同的 Office 365 租户进行了尝试,结果相同。

这以前有效。关于为什么这停止工作的任何想法? uploadUrl 指向我的 SharePoint 端点而不是图形 API 是否正确?

我还应该补充一点,不可恢复的直接上传到图表 API 工作正常。

欢迎提出任何建议。

编辑

这似乎受您上传的文件名长度的影响:

myfile-123100000000000000000000000.txt 运行成功

myfile-1231000000000000000000000000.txt 失败

根据 documentation:

Including the Authorization header when issuing the PUT call may result in a HTTP 401 Unauthoized response. The Authoization header and bearer token should only be sent when issueing the POST during the first step. It should be not be included when issueing the PUT.

如果您从 PUT 调用中删除 Authorization: Bearer XXX header 应该可以解决此问题。

这已被 Microsoft 确认为错误,并于 2017 年 4 月 29 日星期六/星期日 30 日修复。