以其他格式下载文件Download a file in another format

命名空间:microsoft.graphNamespace: microsoft.graph

使用此 API 检索特定格式的项的内容。Use this API to retrieve the contents of an item in a specific format. 并非所有文件都可转换成全部格式。Not all files can be converted into all formats.

若要下载原始格式的项目,请参阅下载项内容To download the item in its original format, see download an item's contents.

先决条件Prerequisites

应用必须拥有用户授予的对应用要转换的文件的读取权限,才能调用此 API。To call this API, the user must have granted the application read access to the file the app wishes to convert.

HTTP 请求HTTP request

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

查询参数Query parameters

参数Parameter 类型Type 说明Description
formatformat stringstring 指定应以何种格式下载项内容。Specify the format the item's content should be downloaded as.

格式选项Format options

以下值对于 format 参数有效:The following values are valid for the format parameter:

格式值Format value 说明Description 支持的源扩展名Supported source extensions
pdfpdf 将项转换成 PDF 格式。Converts the item into PDF format. csv、doc、docx、odp、ods、odt、pot、potm、potx、pps、ppsx、ppsxm、ppt、pptm、pptx、rtf、xls、xlsxcsv, doc, docx, odp, ods, odt, pot, potm, potx, pps, ppsx, ppsxm, ppt, pptm, pptx, rtf, xls, xlsx

可选的请求标头Optional request headers

名称Name Value 说明Description
if-none-matchif-none-match StringString 如果包含此请求标头,且提供的 eTag(或 cTag)与文件中的当前标记不匹配,则返回 HTTP 304 Not Modified 响应。If this request header is included and the eTag (or cTag) provided matches the current tag on the file, an HTTP 304 Not Modified response is returned.

示例Example

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

响应Response

返回 302 Found 响应,重定向到已转换文件的已预先验证的下载 URL。Returns a 302 Found response redirecting to a pre-authenticated download URL for the converted file.

应用必须遵循响应中的 Location 头,才能下载已转换的文件。To download the converted file, your app must follow the Location header in the response.

已预先验证的 URL 仅在短期(几分钟)内有效,无需 Authorization 头即可访问。Pre-authenticated URLs are only valid for a short period of time (a few minutes) and do not require an Authorization header to access.

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

错误响应Error responses

请参阅错误响应,详细了解错误返回方式。See Error Responses for more information about how errors are returned.