无法使用驱动器api下载文件

时间:2018-01-05 15:00:32

标签: office365 onedrive

在过去两周内,我一直看到越来越多的文件在使用驱动器API时无法下载。

服务器似乎在下载过程中切断了连接。

以下是一个例子:

GET https://fakeurl-my.sharepoint.com/personal/myname_fake_com/_api/v2.0/drive/items/01ECRXEPLHILPQGEURXJFK4KZIZAB2KN3F

响应:

{
    "@odata.context": "https://myname-my.sharepoint.com/personal/myname_fake_com/_api/v2.0/$metadata#items/$entity",
    "@odata.type": "#oneDrive.item",
    "@odata.id": "https://fake-my.sharepoint.com/personal/myname_fake_com/_api/v2.0/drive/items/01ECRXEPLHILPQGEURXJFK4KZIZAB2KN3F",
    "@odata.editLink": "drive/items/01ECRXEPLHILPQGEURXJFK4KZIZAB2KN3F",
    "@content.downloadUrl": "https://fake-my.sharepoint.com/personal/myname_fake_com/_layouts/15/download.aspx?UniqueId=03df4267-9112-4aba-ae2b-28c803a53765&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvZm9ydHJlc3NpbnZlc3RtZW50Z3JvdXAtbXkuc2hhcmVwb2ludC5jb21AMDdiZWYwMzEtNjdlOC00ZjU2LWE2M2MtMTBhOWYwNDY2Nzc0IiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTUxNTE2Mjk4NiIsImV4cCI6IjE1MTUxNjY1ODYiLCJlbmRwb2ludHVybCI6IlRKUkw5WFlYTzY5KzBvZkh3TXgzZE9uYXNFd1BNNFMwcVdWb1pOVkJWb289IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxNjkiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6IlpEUTRaVE5rT1dVdFlUQXdZeTAxTURBd0xUQm1ZVFF0TURFeU1qSTVOemhpTkRjMyIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJZMkl5WlRJNVlUSXROamRpTmkwMFpUVmtMV0psTXpBdE1ERTNNelExWWpBNFpHSmkiLCJhcHBfZGlzcGxheW5hbWUiOiJTcGFubmluZyBCYWNrdXAiLCJuYW1laWQiOiI3MDdiNjc2Ny1hOTRkLTQ5NTMtOWViMi04ZDI0ZTk4MzU4NDhAMDdiZWYwMzEtNjdlOC00ZjU2LWE2M2MtMTBhOWYwNDY2Nzc0Iiwicm9sZXMiOiJhbGxzaXRlcy5mdWxsY29udHJvbCIsInR0IjoiMSIsInVzZVBlcnNpc3RlbnRDb29raWUiOm51bGx9.WHBCc0RvdC9aOS9rcHRWNXBMYUlVYWxvVHVTRFlORFZ3aDJjcnRFYmR4OD0&ApiVersion=2.0",
    "createdBy": {
        "user": {
            "email": "myname@fake.com",
            "id": "b9006b02-228f-481b-a0c1-xxxxxxxxx",
            "displayName": "Fake Name"
        }
    },
    "createdDateTime": "2017-12-01T13:50:33Z",
    "eTag": "\"{03DF4267-9112-4ABA-AE2B-28C803A53765},1\"",
    "id": "01ECRXEPLHILPQGEURXJFK4KZIZAB2KN3F",
    "lastModifiedBy": {
        "user": {
            "email": "myname@fake.com",
            "id": "b9006b02-228f-481b-a0c1-7b1cc6802435",
            "displayName": "Fake User"
        }
    },
    "lastModifiedDateTime": "2017-12-01T13:50:33Z",
    "name": "Open Notebook.onetoc2",
    "parentReference": {
        "driveId": "b!oikuy7ZnXU6-MAFzRbCNu1ZsW-M5LqtEiTgGcmCLDPH87jfUKtlDT69Imd4dxRTq",
        "driveType": "business",
        "id": "01ECRXEPNFSYWD4HTYDRHIHHGKT3DX3MDB",
        "path": "/drive/root:/Test sync to PC/OneNote_RecycleBin"
    },
    "webUrl": "https://fake-my.sharepoint.com/personal/mynae_fake_com/_layouts/WopiFrame.aspx?sourcedoc=%7B03DF4267-9112-4ABA-AE2B-28C803A53765%7D&file=Open%20Notebook.onetoc2&action=default",
    "cTag": "\"c:{03DF4267-9112-4ABA-AE2B-28C803A53765},1\"",
    "file": {
        "mimeType": "application/octet-stream"
    },
    "fileSystemInfo": {
        "createdDateTime": "2017-12-01T13:50:33Z",
        "lastModifiedDateTime": "2017-12-01T13:50:33Z"
    },
    "size": 2565
}

证明该文件存在。现在我想要检索它。

curl -L -v -H 'Authorization: Bearer JWTTOKEN' https://fakegroup-my.sharepoint.com/personal/myname_fake_com/_api/v2.0/drive/items/01ECRXEPLHILPQGEURXJFK4KZIZAB2KN3F/content


*   Trying 13.107.6.151...
* TCP_NODELAY set
* Connected to fakegroup-my.sharepoint.com (13.107.6.151) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.sharepoint.com
* Server certificate: Microsoft IT SSL SHA2
* Server certificate: Baltimore CyberTrust Root
> GET /personal/myname_fake_com/_api/v2.0/drive/items/01ECRXEPLHILPQGEURXJFK4KZIZAB2KN3F/content HTTP/1.1
> Host: fakegroup-my.sharepoint.com
> User-Agent: curl/7.51.0
> Accept: */*
> Authorization: Bearer JWTTOKEN



< HTTP/1.1 302 Found
< Cache-Control: private, max-age=0
< Content-Type: application/octet-stream
< Expires: Thu, 21 Dec 2017 14:41:58 GMT
< Last-Modified: Fri, 05 Jan 2018 14:41:58 GMT
< Location: https://fakegroup-my.sharepoint.com/personal/myname_fake_com/_layouts/15/download.aspx?UniqueId=03df4267-9112-4aba-ae2b-28c803a53765&Translate=false&tempauth=atempauthtoken&ApiVersion=2.0
< P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
< X-SharePointHealthScore: 0
< X-SP-SERVERSTATE: ReadOnly=0
< ODATA-VERSION: 4.0
< X-Download-Options: noopen
< Content-Disposition: attachment
< SPClientServiceRequestDuration: 81
< SPRequestDuration: 122
< X-AspNet-Version: 4.0.30319
< SPRequestGuid: 258f3d9e-701b-5000-b449-3a3e4a026425
< request-id: 258f3d9e-701b-5000-b449-3a3e4a026425
< MS-CV: nj2PJRtwAFC0STo+SgJkJQ.0
< Strict-Transport-Security: max-age=31536000
< X-FRAME-OPTIONS: SAMEORIGIN
< X-Powered-By: ASP.NET
< MicrosoftSharePointTeamServices: 16.0.0.7206
< X-Content-Type-Options: nosniff
< X-MS-InvokeApp: 1; RequireReadOnly
< X-MSEdge-Ref: Ref A: 3F1A8FB58A7748778CE50FDD02750504 Ref B: SN1EDGE0820 Ref C: 2018-01-05T14:41:58Z
< Date: Fri, 05 Jan 2018 14:41:58 GMT
< Content-Length: 0

<
* Curl_http_done: called premature == 0
* Connection #0 to host fakegroup-my.sharepoint.com left intact
* Issue another request to this URL: 'https://fakegroup-my.sharepoint.com/personal/myname_fake_com/_layouts/15/download.aspx?UniqueId=03df4267-9112-4aba-ae2b-28c803a53765&Translate=false&tempauth=mytempauth&ApiVersion=2.0'

* Found bundle for host fakegroup-my.sharepoint.com: 0x7fcbd95034f0 [can pipeline]
* Re-using existing connection! (#0) with host fakegroup-my.sharepoint.com
* Connected to fakegroup-my.sharepoint.com (13.107.6.151) port 443 (#0)
> GET /personal/myname_fake_com/_layouts/15/download.aspx?UniqueId=03df4267-9112-4aba-ae2b-28c803a53765&Translate=false&tempauth=tempauthtoken&ApiVersion=2.0 HTTP/1.1
> Host: fakegroup-my.sharepoint.com
> User-Agent: curl/7.51.0
> Accept: */*
> Authorization: Bearer JWTTOKEN
>
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Length: 2565
< Content-Type: application/onenote
< Accept-Ranges: bytes
< ETag: "{03DF4267-9112-4ABA-AE2B-28C803A53765},1"
< P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
< X-SharePointHealthScore: 0
< X-Download-Options: noopen
< Content-Disposition: attachment;filename*=utf-8''Open%20Notebook%2Eonetoc2;filename="Open Notebook.onetoc2"
< CTag: {03DF4267-9112-4ABA-AE2B-28C803A53765},1,1
< X-AspNet-Version: 4.0.30319
< SPRequestGuid: 258f3d9e-c022-5000-0fa4-018099cad340
< request-id: 258f3d9e-c022-5000-0fa4-018099cad340
< MS-CV: nj2PJSLAAFAPpAGAmcrTQA.0
< Strict-Transport-Security: max-age=31536000
< X-FRAME-OPTIONS: SAMEORIGIN
< X-Powered-By: ASP.NET
< MicrosoftSharePointTeamServices: 16.0.0.7206
< X-Content-Type-Options: nosniff
< X-MS-InvokeApp: 1; RequireReadOnly
< X-MSEdge-Ref: Ref A: CB41267B6CF04447A4B8CE9E4E78312F Ref B: SN1EDGE0820 Ref C: 2018-01-05T14:41:58Z
< Date: Fri, 05 Jan 2018 14:41:58 GMT
<
�/�C��vL���W"v_�(���G�֢ȴ��G?ݚ�I����Ȯ����������ܮ��F���Q��+8jdk����������$`��������7f����O�ml�,������������zV�
��`<[G��_��K��<��Ӛ`��[G��_��K��<��Ӛ��������K�3������zV�

                                                       `��[G��_��K��<��Ӛ��������K�3��
* SSLRead() return error -9806
* Curl_http_done: called premature == 1
* Closing connection 0
curl: (56) SSLRead() return error -9806

因此,当调用/ content api时,我们会发出一个302,它会重定向到带有临时身份验证的下载URL。临时身份验证是否可能在下载完成之前到期?

我一直在为此获得相同的结果,并尝试了各种客户端来检索文件(POSTMAN,curl,apache http)。

或者,这是某种类型的回归,基础设施是否为这些文件提供服务?

2 个答案:

答案 0 :(得分:0)

download.aspx如何处理幻影文件似乎存在错误。不幸的是,你无法解决这个问题,但幸运的是,修复非常简单,所以我们希望很快能解决它。

答案 1 :(得分:0)

处理这个问题非常简单。当您尝试下载文件但获得重定向响应( HTTP代码302 )时,请重试您的请求。您可以使用location回复标头值。将此值存储在某处。如果您实现以编程方式下载文件的工具,则所有调用都需要具有重试能力。只需获取之前获得的location回复标头值,然后使用它发送新请求。如果您只是在玩api,那么您应该使用location回复标题中的网址值重新发送请求。