js 文件下载进度监控


 1     var xhr = new XMLHttpRequest();
 2     xhr.open('GET', '文件地址.mp4');
 3     xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 4     xhr.responseType = "blob";
 5     xhr.onprogress = function (event) {
 6         if (event.lengthComputable) {
 7             console.log(event.loaded);
 8             console.log(event.total);12         }
13     };
14     xhr.onload = function (oEvent) {
15         console.log(oEvent);
16         console.log(xhr.status);
17         console.log(xhr.response);
18         if (xhr.readyState === 4 && xhr.status === 200) {
19             // var name = xhr.getResponseHeader("Content-disposition");
20             // var filename = name.substring(20,name.length);
21             var blob = new Blob([xhr.response], {type: 'video/mp4'});
22             var csvUrl = URL.createObjectURL(blob);
23             var link = document.createElement('a');
24             link.href = csvUrl;
25             link.download = 'abababababba.mp4';
26             link.click();          
27         }
28     }
29     xhr.send();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM