Edit

Share via


Get file by contentStream

Namespace: microsoft.graph

Important

APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.

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

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.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}/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

Optional query parameters

This method doesn't support the OData query parameters to help customize the response.

Request headers

Name Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.
Prefer: forceInfectedDownload If provided, the request can download an infected file. For delegated requests, if the tenant setting DisallowInfectedFileDownload is enabled, only tenant administrators or global administrators might download the file. Application-only requests download an infected file regardless of tenant settings. Optional.
Range bytes={range-start}-{range-end}/{size}. Optional. Use to download a partial range of bytes from the file. Specified in RFC 2616.

Request body

Don't supply a request body for this method.

Response

If successful, this method returns a 200 OK HTTP response code.

Examples

Example 1: Download file contents

The following example shows how to download a file.

Request

GET https://graph.microsoft.com/beta/drives/b!fMInbiL5dkK51VbATG0ddrCg6AJpEj9Lm4uGj5HgEi4guyuYp4W5SbH4dPfXTbCF/items/014Y52UITTNSVUQI43PZBJMKLAY6LJBUVE/contentStream

Response

The following example shows the response.

HTTP/1.1 200 OK
Content-Type: text/plain

<File Content>

Example 2: Download a partial range of bytes

To download a partial range of bytes from the file, your app can use the Range header, as specified in RFC 2616.

Request

GET https://graph.microsoft.com/beta/drives/b!fMInbiL5dkK51VbATG0ddrCg6AJpEj9Lm4uGj5HgEi4guyuYp4W5SbH4dPfXTbCF/items/014Y52UITTNSVUQI43PZBJMKLAY6LJBUVE/contentStream
Range: bytes=0-1023

Response

The call returns a 206 Partial Content HTTP response with the requested range of bytes from the file. If the range can't be generated, the Range header is ignored and a 200 OK HTTP response is returned with the full contents of the file.

HTTP/1.1 206 Partial Content
Content-Type: text/plain

<First 1024 bytes of the file>