文件下載響應頭的設置
content-type
指示響應內容的格式
content-disposition
指示如何處理響應內容。
一般有兩種方式:
inline
:直接在頁面顯示attchment
:以附件形式下載
Server 端實現文件下載
- 打開文件,將文件內容寫入到 reponse 中
- 設置 Response header(
content-disposition
,content-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