使用Graph API 将文件上传到 OneDrive for Business时,我有时会看到驱动器项目在PUT
请求后的大小错误。我知道 OneDrive 可能会即时修改 Office 文件,但我也看到纯文本文件也会发生这种情况。
在下面的示例中,我将字符串first version
(13 个字节)写入新的驱动器项。
PUT https://graph.microsoft.com/v1.0/drives/b!e8-Jy2tSiUy2AJBZzvZxc3DIh8dRoG9DrM6MEcF_oxinj1yhH9A8RYDHeCfkxipc/items/root:/onedrive-public-kuvgpshldglnfidf.
txt:/content
不要认为这很重要,但我将Content-Type
标题设置为application/octet-stream
. Graph API 返回状态码 201(如预期)和响应:
{
"@odata.context": "https:\/\/graph.microsoft.com\/v1.0\/$metadata#drives('b%21e8-Jy2tSiUy2AJBZzvZxc3DIh8dRoG9DrM6MEcF_oxinj1yhH9A8RYDHeCfkxipc')\/items\/$entity",
"@microsoft.graph.downloadUrl": "https:\/\/REDACTED.sharepoint.com\/sites\/go-test-onedrive-kuvgpshldglnfidf\/_layouts\/15\/download.aspx?UniqueId=ce025490-d7ee-438a-ac00-a817784e7ea7&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvemVid2FyZXRlc3Quc2hhcmVwb2ludC5jb21AYzBkYjg4MTAtZGZjOS00ODM5LTgyMzQtNTkzNjQwODUzZWQyIiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTU5OTQ2Mjc3MyIsImV4cCI6IjE1OTk0NjYzNzMiLCJlbmRwb2ludHVybCI6IktpSTJyNGo0MVN3MnJhQlVRNG90Mmo1bzIrMEdtbVJBV1grYWNEQzg0bVk9IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxNjIiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6Ik1tVmtOMk0zWVdJdE5EY3dOaTAwWmpjMExXRmpZMll0TVdFM09ESmtPV1V4TkRFMyIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJZMkk0T1dObU4ySXROVEkyWWkwMFl6ZzVMV0kyTURBdE9UQTFPV05sWmpZM01UY3oiLCJhcHBfZGlzcGxheW5hbWUiOiJPcmNoZXN0by0zNjUtMjAyMDA0MjAiLCJuYW1laWQiOiI5YzU1NzQ0OS1mMmY1LTRjNzMtYTYzOC04MThlYjg2YWFkOThAYzBkYjg4MTAtZGZjOS00ODM5LTgyMzQtNTkzNjQwODUzZWQyIiwicm9sZXMiOiJncm91cC5yZWFkIGdyb3VwLndyaXRlIGFsbGZpbGVzLndyaXRlIGFsbHByb2ZpbGVzLnJlYWQiLCJ0dCI6IjEiLCJ1c2VQZXJzaXN0ZW50Q29va2llIjpudWxsfQ.Nm1lSTJML0U1N2dVSzZ2L2MwbkVoc3Fnc0pkbk4wZ0psM1FsWFArWHdTND0&ApiVersion=2.0",
"createdDateTime": "2020-09-07T07:13:03Z",
"eTag": "\"{CE025490-D7EE-438A-AC00-A817784E7EA7},1\"",
"id": "013OPAMZEQKQBM53WXRJB2YAFIC54E47VH",
"lastModifiedDateTime": "2020-09-07T07:13:03Z",
"name": "onedrive-public-kuvgpshldglnfidf.txt",
"webUrl": "https:\/\/REDACTED.sharepoint.com\/sites\/go-test-onedrive-kuvgpshldglnfidf\/Delade%20dokument\/onedrive-public-kuvgpshldglnfidf.txt",
"cTag": "\"c:{CE025490-D7EE-438A-AC00-A817784E7EA7},1\"",
"size": 26,
"createdBy": {
"application": {
"id": "9c557449-f2f5-4c73-a638-818eb86aad98",
"displayName": "REDACTED"
}
},
"lastModifiedBy": {
"application": {
"id": "9c557449-f2f5-4c73-a638-818eb86aad98",
"displayName": "REDACTED"
}
},
"parentReference": {
"driveId": "b!e8-Jy2tSiUy2AJBZzvZxc3DIh8dRoG9DrM6MEcF_oxinj1yhH9A8RYDHeCfkxipc",
"driveType": "documentLibrary",
"id": "013OPAMZF6Y2GOVW7725BZO354PWSELRRZ",
"path": "\/drives\/b!e8-Jy2tSiUy2AJBZzvZxc3DIh8dRoG9DrM6MEcF_oxinj1yhH9A8RYDHeCfkxipc\/root:"
},
"file": {
"mimeType": "text\/plain",
"hashes": {
"quickXorHash": "ZkiDHOZABxDYoQxylUMa3uAGAAA="
}
},
"fileSystemInfo": {
"createdDateTime": "2020-09-07T07:13:03Z",
"lastModifiedDateTime": "2020-09-07T07:13:03Z"
}
}
请注意驱动器项目大小是 26 而不是预期的 13。GET
如果我使用请求获取驱动器项目,则驱动器项目大小仍为 26 。如果我遵循下载 URL,我会得到正确的Content-Length
标题:
$ curl -v -H "Authorization: bearer $TOKEN" $DOWNLOADURL
...
< HTTP/2 200
< cache-control: private
< content-length: 13
< content-type: text/plain
...
first version
跟随下载 URL 时是否可以直接获得正确的驱动器项目大小而无需检查Content-Length
标题?