Download the contents of a DriveItem

Download the contents of the primary stream (file) of a DriveItem. Only driveItems with the file property can be downloaded.

Permissions

One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.

Permission type Permissions (from least to most privileged)
Delegated (work or school account) Files.Read, Files.ReadWrite, Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All
Delegated (personal Microsoft account) Files.Read, Files.ReadWrite, Files.Read.All, Files.ReadWrite.All
Application Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All

HTTP request

GET /drives/{drive-id}/items/{item-id}/content
GET /groups/{group-id}/drive/items/{item-id}/content
GET /me/drive/root:/{item-path}:/content
GET /me/drive/items/{item-id}/content
GET /sites/{siteId}/drive/items/{item-id}/content
GET /users/{userId}/drive/items/{item-id}/content

Optional request headers

Name Value Description
if-none-match String If this request header is included and the eTag (or cTag) provided matches the current tag on the file, an HTTP 304 Not Modified response is returned.

Example

Here is an example to download a complete file.

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

Response

Returns a 302 Found response redirecting to a pre-authenticated download URL for the file. This is the same URL available through the @microsoft.graph.downloadUrl property on the DriveItem.

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

Pre-authenticated download URLs are only valid for a short period of time (a few minutes) and do not require an Authorization header to download.

HTTP/1.1 302 Found
Location: https://b0mpua-by3301.files.1drv.com/y23vmagahszhxzlcvhasdhasghasodfi

Partial range downloads

To download a partial range of bytes from the file, your app can use the Range header as specified in RFC 2616. Note that you must append the Range header to the actual @microsoft.graph.downloadUrl URL and not to the request for /content.

GET https://b0mpua-by3301.files.1drv.com/y23vmag
Range: bytes=0-1023

This will return an HTTP 206 Partial Content response with the request range of bytes from the file. If the range cannot be generated 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
Content-Type: application/octet-stream

<first 1024 bytes of file>

Error responses

See Error Responses for more info about how errors are returned.