| title | Get file by contentStream |
|---|---|
| author | manikantsinghms |
| ms.author | maniksingh |
| description | Download the contents of the primary stream (file) of a driveItem. Only driveItem objects with the file property can be downloaded. |
| ms.localizationpriority | medium |
| ms.date | 3/6/2024 |
| ms.subservice | sharepoint |
| doc_type | apiPageType |
Namespace: microsoft.graph
[!INCLUDE beta-disclaimer]
Download the contents of the primary stream (file) of a driveItem. Only driveItem objects with the file property can be downloaded.
[!INCLUDE national-cloud-support]
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.
[!INCLUDE permissions-table]
[!INCLUDE app-permissions]
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}/contentStreamThis method doesn't support the OData query parameters to help customize the response.
| 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. |
Don't supply a request body for this method.
If successful, this method returns a 200 OK HTTP response code.
The following example shows how to download a file.
GET https://graph.microsoft.com/beta/drives/b!fMInbiL5dkK51VbATG0ddrCg6AJpEj9Lm4uGj5HgEi4guyuYp4W5SbH4dPfXTbCF/items/014Y52UITTNSVUQI43PZBJMKLAY6LJBUVE/contentStream
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
The following example shows the response.
HTTP/1.1 200 OK
Content-Type: text/plain
<File Content>To download a partial range of bytes from the file, your app can use the Range header, as specified in RFC 2616.
GET https://graph.microsoft.com/beta/drives/b!fMInbiL5dkK51VbATG0ddrCg6AJpEj9Lm4uGj5HgEi4guyuYp4W5SbH4dPfXTbCF/items/014Y52UITTNSVUQI43PZBJMKLAY6LJBUVE/contentStream
Range: bytes=0-1023
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
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>