文件下载响应头的设置
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
本文详细介绍了在服务器端实现文件下载时,如何正确设置响应头以指定文件的下载方式。主要内容包括content-type和content-disposition的使用,以及具体的代码示例。
917

被折叠的 条评论
为什么被折叠?



