命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
使用此 API 检索特定格式的项的内容。
并非所有文件都可转换成全部格式。
若要下载原始格式的项目,请参阅下载项内容。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Files.Read |
Files.Read.All、Files.ReadWrite、Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All |
委派(个人 Microsoft 帐户) |
Files.Read |
Files.Read.All、Files.ReadWrite、Files.ReadWrite.All |
应用程序 |
Files.Read.All |
Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All |
HTTP 请求
GET /drive/items/{item-id}/content?format={format}
GET /drive/root:/{path and filename}:/content?format={format}
查询参数
参数 |
类型 |
说明 |
format |
string |
指定应以何种格式下载项内容。 |
以下值对于 format 参数有效:
值 |
说明 |
支持的源扩展名 |
glb |
将项转换为 GLB 格式 |
cool、fbx、obj、ply、stl、3mf |
html |
将项转换为 HTML 格式 |
eml、md、msg |
jpg |
将项转换为 JPG 格式 |
3g2、3gp、3gp2、3gpp、3mf、ai、arw、asf、avi、bas、bash、bat、bmp、c、cbl、cmd、cool、cpp、cr2、crw、cs、css、csv、cur、dcm、dcm30、dic、dicm、dicom、dng、doc、docx、dwg、eml、epi、eps、epsf、epsi、epub、erf、fbx、fppx、gif、glb、h、hcp、heic、heif、htm、html、ico、icon、java、jfif、jpeg、jpg、js、json、key、log、m2ts、m4a、m4v、markdown、md、mef、mov、movie、mp3、mp4、mp4v、mrw、msg、mts、nef、nrw、numbers、obj、odp、odt、ogg、orf、pages、pano、pdf、pef、php、pict、pl、ply、png、pot、potm、potx、pps、ppsx、ppsxm、ppt、pptm、pptx、ps、ps1、psb、psd、py、raw、rb、rtf、rw1、rw2、sh、sketch、sql、sr2、stl、tif、tiff、ts、txt、vb、webm、wma、wmv、xaml、xbm、xcf、xd、xml、xpm、yaml、yml |
pdf |
将项转换为 PDF 格式 |
doc、docx、epub、eml、htm、html、md、msg、odp、ods、odt、pps、ppsx、ppt、pptx、rtf、tif、tiff、xls、xlsm、xlsx |
名称 |
值 |
说明 |
if-none-match |
String |
如果包含此请求标头,且提供的 eTag(或 cTag)与文件中的当前标记不匹配,则返回 HTTP 304 Not Modified 响应。 |
示例
GET /drive/items/{item-id}/content?format={format}
// 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}"].Content.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Format = "{format}";
});
mgc-beta drives items content get --drive-id {drive-id} --drive-item-id {driveItem-id}
// 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"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
//other-imports
)
requestFormat := "{format}"
requestParameters := &graphdrives.ItemItemsItemContentRequestBuilderGetQueryParameters{
Format: &requestFormat,
}
configuration := &graphdrives.ItemItemsItemContentRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
// 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").Content().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}").content().get(requestConfiguration -> {
requestConfiguration.queryParameters.format = "{format}";
});
const options = {
authProvider,
};
const client = Client.init(options);
let stream = await client.api('/drive/items/{item-id}/content?format={format}')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Content\ContentRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new ContentRequestBuilderGetRequestConfiguration();
$queryParameters = ContentRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->format = "{format}";
$requestConfiguration->queryParameters = $queryParameters;
$graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->content()->get($requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Files
Get-MgBetaDriveItemContent -DriveId $driveId -DriveItemId $driveItemId -Format "{format}"
# 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.content_request_builder import ContentRequestBuilder
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
query_params = ContentRequestBuilder.ContentRequestBuilderGetQueryParameters(
format = "{format}",
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').content.get(request_configuration = request_configuration)
响应
返回 302 Found
响应,重定向到已转换文件的已预先验证的下载 URL。
应用必须遵循响应中的 Location
头,才能下载已转换的文件。
预验证 URL 仅在几分钟) (短时间内有效,不需要 Authorization
标头即可访问。
HTTP/1.1 302 Found
Location: https://b0mpua-by3301.files.1drv.com/y23vmagahszhxzlcvhasdhasghasodfi
错误响应
有关 错误 返回方式的详细信息,请参阅错误响应。