4. Content-Disposition 詳解

文件下載響應頭的設置

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章