Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

下载文件问题

image.png
为什么我下载压缩包是下完了 才出现这个弹窗
image.png
正常流程不是一点下载就弹出窗来了 然后一点一点长进度


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

应该是你没有返回正确的 HTTP Response Header

加入以下 Header 可以告知浏览器明确这是下载一个 zip 文件

  • Content-Type: application/zip
  • Content-Disposition: attachment; filename="your_zip_filename.zip"

如果你希望让浏览器显示正确的下载进度, 还需要返回文件的长度

  • Content-Length: 10000 // 指 10000 字节

另外, 留意到你的截图是 XHR, 很可能前端访问方式有误, 应该让浏览器直接打开, 而不是通过 fetch / XMLHttpRequest 等方式打开


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...