以其他格式下载文件

命名空间:microsoft.graph

重要

Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。

使用此 API 检索特定格式的项的内容。 并非所有文件都可转换成全部格式。

若要下载原始格式的项目,请参阅下载项内容。

此 API 可用于以下国家级云部署。

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国
✅ ✅ ✅ ✅

权限

为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。

权限类型 最低特权权限 更高特权权限
委派(工作或学校帐户) Files.Read Files.ReadWrite, Files.Read.All, Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All
委派(个人 Microsoft 帐户) Files.Read Files.ReadWrite, Files.Read.All, Files.ReadWrite.All
应用程序 Files.ReadWrite.All Sites.ReadWrite.All

注意

SharePoint Embedded 需要访问 FileStorageContainer.Selected 容器内容的权限。 此权限与前面提到的权限不同。 除了 Microsoft Graph 权限外,应用还必须具有调用此 API 所需的 容器类型权限 。 有关详细信息,请参阅 SharePoint Embedded 身份验证和授权。

HTTP 请求

GET /me/drive/items/{item-id}/content?format={format}
GET /me/drive/root:/{path and filename}:/content?format={format}
GET /drive/items/{item-id}/content?format={format}
GET /drive/root:/{path and filename}:/content?format={format}

查询参数

参数 类型 说明
format String 指定应以何种格式下载项内容。
height Int32 转换后的图像的所需高度(以像素为单位)。 这种情况下需要。format=jpg
宽度 Int32 转换后的图像所需的宽度(以像素为单位)。 这种情况下需要。format=jpg

以下值对于 format 参数有效:

值 说明 支持的源扩展名
glb 将项转换为 GLB 格式 cool、fbx、obj、ply、stl、3mf
html 将项转换为 HTML 格式 循环、流体、wbtx、白板
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, dot, dotx, dotm, dsn, dwg, eml, epub, fluidframework, form, htm, html, loop, loot, markdown, md, msg, note, odp, ods, odt, page, pps, ppsx, ppt, pptx, pulse, rtf, task, tif, tiff, wbtx, whiteboard, xls, xlsm, xlsx

可选的请求标头

名称 值 说明
if-none-match String 如果包含此请求标头,且提供的 eTag(或 cTag)与文件中的当前标记不匹配,则返回 HTTP 304 Not Modified 响应。

示例

GET /drive/items/{item-id}/content?format={format}

响应

返回 302 Found 响应,重定向到已转换文件的已预先验证的下载 URL。

应用必须遵循响应中的 Location 头,才能下载已转换的文件。

经过预身份验证的 URL 仅在短时间内有效, (几分钟) ,不需要 Authorization 标头即可访问。

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

错误响应

有关如何返回错误的详细信息,请参阅 错误响应 。