Skip to main content
GET
下载文件

Authorizations

Authorization
string
header
required

每个请求都通过 API 密钥认证:Authorization: Bearer {API_KEY}。应用接口使用应用 API 密钥,知识库接口使用知识库 API 密钥(快速开始)。

API 密钥应保存在服务端,切勿嵌入客户端代码。缺失或无效的密钥会返回 HTTP 401(unauthorized)。

Path Parameters

file_id
string<uuid>
required

要下载的文件 ID,来自上传文件的响应。

Query Parameters

as_attachment
boolean
default:false

为 true 时,文件以附件形式下载,而不是在浏览器中内联渲染。

user
string

终端用户标识,由你的应用定义,需在应用内唯一。此处对文件访问没有影响,文件访问按应用和消息(而非 user)限定。参见 终端用户身份。

Response

返回原始文件内容,在浏览器中内联显示,Content-Type 为文件的 MIME 类型。as_attachment 为 true 时改为下载:Content-Type 为 application/octet-stream,并带有 Content-Disposition: attachment。

以下文件即使 as_attachment 为 false,也按这种方式下载:

  • HTML、XHTML、XML 和 XSL 文件(按 MIME 类型 text/html、application/xml、text/xml、text/xsl 或除 SVG 外以 +xml 结尾的类型识别,或按扩展名 .html、.htm、.xhtml、.xht、.xml、.xsl、.xslt 识别)
  • 压缩的 SVG 文件(.svgz)
  • 没有 MIME 类型的文件

SVG 文件是例外:MIME 类型为 image/svg+xml 或扩展名为 .svg 的文件,即使同时符合上面的列表,在 as_attachment 为 false 时仍以 image/svg+xml 内联显示。沙箱会阻止其中的脚本运行。

The response is of type file.