When uploading files to OneDrive for Business using the Graph API I sometimes see that the drive item has the wrong size after the PUT
request. I know that OneDrive might modify Office files on the fly but I see it happening for plain text files too.
In example below I write the string first version
(13 bytes) to a new drive item.
PUT https://graph.microsoft.com/v1.0/drives/b!e8-Jy2tSiUy2AJBZzvZxc3DIh8dRoG9DrM6MEcF_oxinj1yhH9A8RYDHeCfkxipc/items/root:/onedrive-public-kuvgpshldglnfidf.
txt:/content
Don't think it matters but I set the Content-Type
header to application/octet-stream
. Graph API returns status code 201 (as expected) and the response:
{
"@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"
}
}
Notice how drive item size is 26 and not 13 as expected. The drive item size is still 26 if I fetch the drive item using a GET
request. If I follow the download URL I get the correct Content-Length
header though:
$ curl -v -H "Authorization: bearer $TOKEN" $DOWNLOADURL
...
< HTTP/2 200
< cache-control: private
< content-length: 13
< content-type: text/plain
...
first version
Is it possible to get the correct drive item size directly without having to check the Content-Length
header when following the download URL?