OneDrive v7.2 File Picker

Copper Contributor
  1.   I need to know the api that is being called when a file is picked for both personal and business ( drive or site files ). It looks like https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/?select=id,name,size,@content.dow... is being called. Am I correct ?
  2.   The returned response only contains the fields mentioned in the select. But I am using this to fetch the file using graph api. It looks like I can't fetch the file unless drive-id is mentioned if the file is picked from sharepoint site. I can only get the itemId from the response. Is it possible to find the drive-id from the above response. As far as I have seen the drive id is only returned in @odata.context as https://graph.microsoft.com/v1.0/$metadata#drives({drive-id})/items/$entity. Can anyone help me on how to retrieve the file details using the response obtained ?
3 Replies

@Harsha2470 

Yes, you are correct. The OneDrive File Picker JavaScript SDK v7.2 uses the Microsoft Graph API to interact with files on OneDrive1.

 

When a file is picked, an API call is made to https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/?select=id,name,size,@content.dow....

 

The response from this API call only contains the fields specified in the select parameter1. If you need the drive-id, it is indeed only returned in the @odata.context as https://graph.microsoft.com/v1.0/$metadata#drives({drive-id})/items/$entity.

 

If you’re using this to fetch a file using the Graph API and the file is picked from a SharePoint site, you would indeed need the drive-id. Unfortunately, the drive ID is not included in the standard response from the file picker1. You might need to make an additional API call to retrieve this information.

Please note that this information is based on the OneDrive File Picker JavaScript SDK v7.2 documentation and may vary with different versions or updates

 

If I have answered your question, please mark your post as Solved

If you like my response, please give it a Like :smile:

Appreciate your Kudos! Proud to contribute! :)

 

But I need driveId for the sharepoint sites to hit the specified Graph API, is it recommended to retrieve it from @odata.context or will it cause any concerns caused by this ?
Is there any API to retrieve the drive Id by the obtained response from the oneDrive File Picker v7.2

as it only contains the file id, name, odata.context, downloadurl ?

Thanks in Advance

@Harsha2470 

To retrieve the driveId for SharePoint sites, you can use the Microsoft Graph API. You can use the @odata.context property to obtain the driveId of the SharePoint site. The @odata.context property is a JSON object that contains metadata about the response. It includes a URL that points to the metadata document for the response. You can use this URL to retrieve the driveId of the SharePoint site.

 

There is no direct API to retrieve the driveId from the response obtained from OneDrive File Picker v7.2. However, you can use the Microsoft Graph API to retrieve the driveId. You can use the fileId obtained from OneDrive File Picker v7.2 to make a request to Microsoft Graph API and retrieve the driveId.

Here is an example of how you can retrieve the driveId using Microsoft Graph API:

-GET /v1.0/drives/{drive-id}/items/{item-id}

-You can replace {drive-id} with the ID of the drive and {item-id} with the ID of the file obtained from OneDrive File Picker v7.2.

 

In summary

The OneDrive File Picker JavaScript SDK v7.2 uses the Microsoft Graph API to interact with files on OneDrive1. When a file is picked, an API call is made to https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/?select=id,name,size,@content.dow....

 

However, it seems that the OneDrive File Picker v7.2 does not directly provide the driveId in its response. It only provides the id, name, downloadUrl, and odata.context.

 

As for using the @odata.context to retrieve the driveId, it’s not clear whether this is a recommended approach or if it could cause any concerns. The official documentation or the OneDrive Developer forum2 might provide more insights on this.

 

If you need to work with SharePoint sites, you might need to use a different approach or API that can provide the driveId for SharePoint sites, as the /me/drive API does not retrieve files attached from SharePoint sites.

 

 

If I have answered your question, please mark your post as Solved

If you like my response, please give it a Like :smile:

Appreciate your Kudos! Proud to contribute! :)