You can now directly download content of a file (of a Driveitem) in a SharePoint Online site through a single call.Â
Previously, while downloading file content via any endpoint mentioned here, you used to get ‘302 Found’ response redirecting to a pre-authenticated download URL (which is the same URL available through the ‘microsoft.graph.downloadurl’ property on the Driveitem) which you had to call again to start the download process. This resulted in redundant calls increasing the network overhead.Â
A new Microsoft Graph endpoint is introduced in BETA to enable you download content of file* through a single call, e.g., when you hit ‘GET /drives/{drive-id}/items/{item-id}/contentStream’, it will start downloading the content from the stated drive-id directly. Â
*Please note, only driveitem objects with the ‘file’ property can be downloaded.Â
What are the benefits?Â
The new endpoint improves network performance by eliminating redundant calls and enhances security by enabling direct streaming.Â
How do I use it?Â
Call any of the following endpoints to get started:Â
Please use ‘BETA’ version.Â
GET /drives/{drive-id}/items/{item-id}/contentStreamÂ
GET /groups/{group-id}/drive/items/{item-id}/contentStreamÂ
GET /me/drive/root:/{item-path}:/contentStreamÂ
GET /me/drive/items/{item-id}/contentStreamÂ
GET /shares/{shareIdOrEncodedSharingUrl}/driveItem/contentStreamÂ
GET /sites/{siteId}/drive/items/{item-id}/contentStreamÂ
GET /users/{userId}/drive/items/{item-id}/contentStreamÂ
For more details, please refer to this document.Â
With the pre-authenticated downloadURL we effectively got a snapshot of the item at that point in time and could download it in chunks using the range headers etc… With the stream endpoint, if the file is modified mid stream how is that handled? Will it abort or are we effectively streaming a snapshot tied to the connection session etc..?
The enhanced endpoint enables you download directly without being redirected through pre-authenticated url but the download process remains same. So, you can still download partial content using range headers and it will enable download of realtime content, which means, if any byte is modified and synced before download, you will get updated content.
Great work! Will this also work with etags ?
Thank you! Yes, this is expected to work with etags.
We have implemented it in our application and it is working well! However we do not get the etag in the response headers. Any guidance on how to use etags with this endpoint (this is key)?
Even better! 🙂 Any expectation on when it will hit v1?