How to get a temporary (or permanent) regular URL for a file in OneDrive using the Microsoft Graph API

烈酒焚心 提交于 2021-02-20 05:06:58

问题


Using createLink, for example with the POST parameters: {"type": "view", "scope": "anonymous"}, you get a response including a webUrl which will open the item (in read-only or read-write mode, depending on the POST parameters) in Office Online. Because of the 'anonymous' scope, anyone (no login required) can open the office online page.

Unfortunately, I don't a link to Office Online, and it looks like this is the functionality provided by Create a sharing link for a DriveItem.

I need a link to the actual file (to download it). Something like many other 'files' APIs allow. This is, generate a time-limited (or permanent) URL to file.

Is this possible?

EDIT: Clarification: Download the contents of a DriveItem (i.e. a Stream) is not what I'm looking for.


回答1:


There are four ways of linking to a file in OneDrive via Microsoft Graph:

  • The web preview for the file, which is accessed from the webUrl property of DriveItem. This requires the user to be signed in to access.
  • The WebDAV URL for the file, which is accessed from the webDavUrl property of DriveItem. This also requires the user to be signed in to access, but is a direct link to the file. Note: this is available via Microsoft Graph, but is only documented on dev.onedrive.com.
  • Creating a sharing link, which provides anonymous or organization restricted access to the web preview of the file.
  • Download link, which is a short-duration URL available to download the contents of the file programmatically.

It sounds like webDavUrl might be the link you are looking for.



来源:https://stackoverflow.com/questions/40052280/how-to-get-a-temporary-or-permanent-regular-url-for-a-file-in-onedrive-using-t

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