文章目录

  • 文件下载响应头的设置
  • Server 端实现文件下载

文件下载响应头的设置

content-type 指示响应内容的格式

content-disposition 指示如何处理响应内容。

一般有两种方式:

  • inline:直接在页面显示
  • attchment:以附件形式下载

Server 端实现文件下载

  1. 打开文件,将文件内容写入到 reponse 中
  2. 设置 Response header(content-dispositioncontent-type

代码示例:

Content-Type: application/octet-stream
Content-Disposition: attachment;filename=2018-03-03_15-47-45--2019-03-03_15-48-13--73c75b84-ba2a-470f-a713-07216fcd214b.xlsx

更多推荐

4. Content-Disposition 详解