Sharepoint Graph API strange behaviour while trying to get download link for a file

大兔子大兔子 提交于 2020-06-17 15:53:09

问题


I'm trying to get file content. When I'm calling

GET /sites/{site-id}/drive/root:/{item-path}

Response contains all information about the file, but no @microsoft.graph.downloadUrl field is returned.

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('domain.sharepoint.com%2Ccc252463-cda2-3eb2-b15e-8836305f1420%2Cc0db7f82-b16f-4fe5-9885-7e434b11e5b8')/drives('b%21k3l2zKLNsk50Log2MF7UIBtTYFV32M5EtW4ZTyYF38gyZs2y-wOfSL0tPWbYys-4')/root/$entity", 
  "cTag": "\"c:{0e8182ec-5ee9-41e6-96ba-372340f873cb},1\"", 
  "createdBy": {
    "user": {
      "displayName": "Slava", 
      "email": "slava@domain.onmicrosoft.com", 
      "id": "1bf758e3-d0f7-1111-88a9-7e13f98efa01"
    }
  }, 
  "createdDateTime": "2020-03-22T20:29:23Z", 
  "eTag": "\"{0E8182EC-5EE9-41E6-96BA-372340F873CB},1\"", 
  "file": {
    "hashes": {
      "quickXorHash": "cwjdhie41VYT6k3bdKT/y30bKX0="
    }, 
    "mimeType": "application/pdf"
  }, 
  "fileSystemInfo": {
    "createdDateTime": "2020-03-22T20:29:23Z", 
    "lastModifiedDateTime": "2020-03-22T20:29:23Z"
  }, 
  "id": "01J7TAN47MQKAQ52K64ZAZNORXENAPQ46L", 
  "lastModifiedBy": {
    "user": {
      "displayName": "Slava", 
      "email": "slava@domain.onmicrosoft.com", 
      "id": "1bf758e3-d0f7-1111-88a9-7e13f98efa01"
    }
  }, 
  "lastModifiedDateTime": "2020-03-22T20:29:23Z", 
  "name": "A Survey of Applications of Markov Decision Processes.pdf", 
  "parentReference": {
    "driveId": "b!k3l2zKLNsk50Log2MF7UIBtTYFV32M5EtW4ZTyYF38gyZs2y-wOfSL0tPWbYys-4", 
    "driveType": "documentLibrary", 
    "id": "01J7TAN456Y2GOVW7725BZO354PWSELRRZ", 
    "path": "/drives/b!k3l2zKLNsk50Log2MF7UIBtTYFV32M5EtW4ZTyYF38gyZs2y-wOfSL0tPWbYys-4/root:"
  }, 
  "size": 6590404, 
  "webUrl": "https://domain.sharepoint.com/sites/Test/Shared%20Documents/A%20Survey%20of%20Applications%20of%20Markov%20Decision%20Processes.pdf"
}

Also if in headers for the GET I don't put:

Prefer="apiversion=2.1"

I'm getting error that item is not found (Tried in postman and code). If I change to :

GET /sites/{site-id}/drive/root:/{item-path}:/content

Then I'm getting 302 response with Location header with the URL, so now to be able to get content from Sharepoint file and validate that file downloaded is fine (using hash), I need to do 3 calls , first to get all file metadata, then call to get Location URL and then real call to get a content.

So, two questions:

  1. Why I can't get @microsoft.graph.downloadUrl in /sites/{site-id}/drive/root:/{item-path}
  2. Why without prefer header item is not found ?

Please advise. Thanks

来源:https://stackoverflow.com/questions/61678111/sharepoint-graph-api-strange-behaviour-while-trying-to-get-download-link-for-a-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!