Espace de noms: microsoft.graph
Importante
Les API sous la version /beta dans Microsoft Graph sont susceptibles d’être modifiées. L’utilisation de ces API dans des applications de production n’est pas prise en charge. Pour déterminer si une API est disponible dans v1.0, utilisez le sélecteur Version .
Téléchargez le contenu du flux principal (fichier) d’une ressource driveItem. Seuls les objets driveItem avec la propriété de fichier peuvent être téléchargés.
Cette API est disponible dans les déploiements cloud nationaux suivants.
| Service global |
Gouvernement américain L4 |
Gouvernement américain L5 (DOD) |
Chine exploitée par 21Vianet |
| ✅ |
✅ |
✅ |
✅ |
Autorisations
Choisissez l’autorisation ou les autorisations marquées comme étant les moins privilégiées pour cette API. Utilisez une ou plusieurs autorisations privilégiées uniquement si votre application en a besoin. Pour plus d’informations sur les autorisations déléguées et d’application, voir Types d’autorisations. Pour en savoir plus sur ces autorisations, consultez la référence des autorisations.
| Type d’autorisation |
Autorisations les moins privilégiées |
Autorisations à privilèges plus élevés |
| Déléguée (compte professionnel ou scolaire) |
Files.Read |
Files. ReadWrite, Files. Read.All, Files. ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All |
| Déléguée (compte Microsoft personnel) |
Files.Read |
Files. ReadWrite, Files. Read.All, Files. ReadWrite.All |
| Application |
Files.Read.All |
Files. ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All |
Remarque
SharePoint Embedded nécessite l’autorisation FileStorageContainer.Selected pour accéder au contenu du conteneur. Cette autorisation est différente de celles mentionnées précédemment. Outre les autorisations Microsoft Graph, votre application doit disposer des autorisations de type conteneur nécessaires pour appeler cette API. Pour plus d’informations, consultez Authentification et autorisation SharePoint Embedded.
Requête HTTP
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
Paramètres facultatifs de la requête
Cette méthode ne prend pas en charge les paramètres de requête OData pour personnaliser la réponse.
| Nom |
Description |
| Autorisation |
Porteur {token}. Obligatoire. En savoir plus sur l’authentification et les autorisations. |
| Préférer : forceInfectedDownload |
Si elle est fournie, la demande peut télécharger un fichier infecté. Pour les demandes déléguées, si le paramètre de locataire DisallowInfectedFileDownload est activé, seuls les administrateurs de client ou les administrateurs généraux peuvent télécharger le fichier. Les demandes d’application uniquement téléchargent un fichier infecté, quels que soient les paramètres du locataire. Facultatif. |
| Plage |
bytes={range-start}-{range-end}/{size}. Facultatif. Permet de télécharger une plage partielle d’octets à partir du fichier. Spécifié dans RFC 2616. |
Corps de la demande
N’indiquez pas le corps de la demande pour cette méthode.
Réponse
En cas de réussite, cette méthode renvoie un 200 OK code de réponse HTTP.
Exemples
Exemple 1 : Télécharger le contenu du fichier
L’exemple suivant montre comment télécharger un fichier.
Demande
GET https://graph.microsoft.com/beta/drives/b!fMInbiL5dkK51VbATG0ddrCg6AJpEj9Lm4uGj5HgEi4guyuYp4W5SbH4dPfXTbCF/items/014Y52UITTNSVUQI43PZBJMKLAY6LJBUVE/contentStream
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].ContentStream.GetAsync();
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").ContentStream().Get(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").contentStream().get();
const options = {
authProvider,
};
const client = Client.init(options);
let stream = await client.api('/drives/b!fMInbiL5dkK51VbATG0ddrCg6AJpEj9Lm4uGj5HgEi4guyuYp4W5SbH4dPfXTbCF/items/014Y52UITTNSVUQI43PZBJMKLAY6LJBUVE/contentStream')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->contentStream()->get()->wait();
Import-Module Microsoft.Graph.Beta.Files
Get-MgBetaDriveItemContentStream -DriveId $driveId -DriveItemId $driveItemId
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').content_stream.get()
Réponse
L’exemple suivant illustre la réponse.
HTTP/1.1 200 OK
Content-Type: text/plain
<File Content>
Exemple 2 : Télécharger une plage partielle d’octets
Pour télécharger une plage partielle d’octets à partir du fichier, votre application peut utiliser l’en-tête, comme spécifié dans RFC Range2616.
Demande
GET https://graph.microsoft.com/beta/drives/b!fMInbiL5dkK51VbATG0ddrCg6AJpEj9Lm4uGj5HgEi4guyuYp4W5SbH4dPfXTbCF/items/014Y52UITTNSVUQI43PZBJMKLAY6LJBUVE/contentStream
Range: bytes=0-1023
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].ContentStream.GetAsync((requestConfiguration) =>
{
requestConfiguration.Headers.Add("Range", "bytes=0-1023");
});
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
abstractions "github.com/microsoft/kiota-abstractions-go"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
//other-imports
)
headers := abstractions.NewRequestHeaders()
headers.Add("Range", "bytes=0-1023")
configuration := &graphdrives.ItemItemsItemContentStreamRequestBuilderGetRequestConfiguration{
Headers: headers,
}
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").ContentStream().Get(context.Background(), configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").contentStream().get(requestConfiguration -> {
requestConfiguration.headers.add("Range", "bytes=0-1023");
});
const options = {
authProvider,
};
const client = Client.init(options);
let stream = await client.api('/drives/b!fMInbiL5dkK51VbATG0ddrCg6AJpEj9Lm4uGj5HgEi4guyuYp4W5SbH4dPfXTbCF/items/014Y52UITTNSVUQI43PZBJMKLAY6LJBUVE/contentStream')
.version('beta')
.header('Range','bytes=0-1023')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\ContentStream\ContentStreamRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new ContentStreamRequestBuilderGetRequestConfiguration();
$headers = [
'Range' => 'bytes=0-1023',
];
$requestConfiguration->headers = $headers;
$graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->contentStream()->get($requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Files
Get-MgBetaDriveItemContentStream -DriveId $driveId -DriveItemId $driveItemId
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.drives.item.items.item.content_stream.content_stream_request_builder import ContentStreamRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_configuration = RequestConfiguration()
request_configuration.headers.add("Range", "bytes=0-1023")
await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').content_stream.get(request_configuration = request_configuration)
Réponse
L’appel retourne une 206 Partial Content réponse HTTP avec la plage d’octets demandée à partir du fichier. Si la plage ne peut pas être générée, l’en-tête Range est ignoré et une 200 OK réponse HTTP est renvoyée avec le contenu complet du fichier.
HTTP/1.1 206 Partial Content
Content-Type: text/plain
<First 1024 bytes of the file>