Edit

Share via


Download contents of a driveItemVersion resource

Namespace: microsoft.graph

Retrieve the contents of a specific version of a driveItem.

Note: Getting the content of the current version is not supported. To do that, use the Download the contents of a driveItem method.

This API is available in the following national cloud deployments.

Global service US Government L4 US Government L5 (DOD) China operated by 21Vianet

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

Permission type Least privileged permissions Higher privileged permissions
Delegated (work or school account) Files.Read Files.Read.All, Files.ReadWrite, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All
Delegated (personal Microsoft account) Files.Read Files.Read.All, Files.ReadWrite, Files.ReadWrite.All
Application Files.Read.All Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All

Note

SharePoint Embedded requires the FileStorageContainer.Selected permission to access the content of the container. This permission is different from the ones mentioned previously. In addition to Microsoft Graph permissions, your app must have the necessary container type permissions to call this API. For more information, see SharePoint Embedded authentication and authorization.

HTTP request

GET /drives/{drive-id}/items/{item-id}/versions/{version-id}/content
GET /groups/{group-id}/drive/items/{item-id}/versions/{version-id}/content
GET /me/drive/items/{item-id}/versions/{version-id}/content
GET /sites/{site-id}/drive/items/{item-id}/versions/{version-id}/content
GET /users/{user-id}/drive/items/{item-id}/versions/{version-id}/content

Request headers

Name Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.

Response

Returns a 302 Found response redirecting to a preauthenticated download URL for the bytes of the file.

To download the contents of the file your application needs to follow the Location header in the response. Many HTTP client libraries will automatically follow the 302 redirection and start downloading the file immediately.

Preauthenticated download URLs are only valid for a short period of time (a few minutes) and don't require an Authorization header to download.

Examples

Example 1: Download the contents of a previous version of a file

This example retrieves a version of a file in the current user's drive.

Request

GET /me/drive/items/{item-id}/versions/{version-id}/content

Response

The call returns a redirect to where the contents of the version can be downloaded.

HTTP/1.1 302 Found
Location: https://onedrive.com/34FF49D6...

Example 2: Download a partial range of bytes from a previous version of a file

To download a partial range of bytes from a driveItemVersion, your app can use the Range header as specified in RFC 2616. You must append the Range header when following the redirect and not to the request for /content.

GET https://onedrive.com/34FF49D6...
Range: bytes=0-1023

The call returns an HTTP 206 Partial Content response with the request range of bytes from the file. If the range can't be generated, then the Range header may be ignored and an HTTP 200 response would be returned with the full contents of the file.

HTTP/1.1 206 Partial Content
Content-Range: bytes 0-1023/2048

<first 1024 bytes of file>

Remarks

OneDrive doesn't preserve the complete metadata for previous versions of a file.

When your app retrieves the list of available versions for a file, a driveItemVersion resource is returned that provides the available information about the specific version.