I am using OneDrive file picker and Graph api to embed documents in my web app, not sure that the correct way.

Jonathan Korach 1 Reputation point
2021-03-09T13:12:45.033+00:00

Hi,

In the doc,driveItem: preview mention that driveItem: preview request generates a short-lived URL, I would like to know what is the expiration of the link (hour, day, week, month, etc..).

More details and to give things into context, in our web app we enable users to upload files, and also upload from their cloud drives, such as Google Drive, DropBox, and OneDrive.

Most of our users are using OneDrive for businesses.

I tried using the request: POST /drives/{driveId}/items/{itemId}/preview , after the user selects the file from the file picker, and I using the getUrl to embed the file into an iframe.(the getURL as src)
I noticed that the URL contains access_token, and I deleted it before saving it, and I noticed that the iframe still works fine, and allows only users with permission to see the file, is this is a good usage of that?

Are there any pitfalls that I didn't notice?

Thank's

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,582 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Deva-MSFT 2,256 Reputation points Microsoft Employee
    2021-03-11T07:46:14.593+00:00

    If you use driveItem: preview, this action allows you to obtain a short-lived embeddable URL for an item in order to render a temporary preview. Unfortunately its not documented about the duration. The preview action is currently only available on SharePoint and OneDrive for Business.

    In case if you want to obtain long-lived embeddable links, use the createLink API instead.