Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 第166天 怎么下载一个zip文件? #1273

Open
haizhilin2013 opened this issue Sep 28, 2019 · 4 comments
Open

[js] 第166天 怎么下载一个zip文件? #1273

haizhilin2013 opened this issue Sep 28, 2019 · 4 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第166天 怎么下载一个zip文件?

@haizhilin2013 haizhilin2013 added the js JavaScript label Sep 28, 2019
@encountermm
Copy link

  1. 请求后台api,后台返回流文件
  2. a标签download属性

@810307015
Copy link

window.open(fileUrl)

@vkboo
Copy link

vkboo commented Sep 29, 2019

  • a标签加download属性
<!-- download:指定下载文件的文件名 -->
<a href="http://somehost/somefile.zip" download="filename.zip">Download file</a>
  • 文件流的方式
var a = document.createElement('a');
var url = window.URL.createObjectURL(blob);
var filename = 'what-you-want.txt';
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
  • 注意:Bolb的方式构建完 blob 对象后才会转换成文件,所以尽量使用a标签的形式进行下载

@xiaoqiangz
Copy link

请求接口返回流文件,再利用a标签 download属性下载。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

5 participants