下载mp4文件
實現(xiàn)mp4文件的下載,而不是在線播放
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body><button onclick="GetFile()">下載</button><script>// 會先下載流,完成后才彈出選擇目錄,所以最好加上進度條function GetFile(){axios({url: `http://image.wangrui8.top/dms-2019-07-22-00-00~1.mp4`, method: 'get',responseType: 'blob',onDownloadProgress (progress){// 這里是下載的進度 console.log(Math.round(progress.loaded / progress.total * 100) + '%');},}).then(res=>{let blobUrl = window.URL.createObjectURL(res.data);let link = document.createElement('a');document.body.appendChild(link);link.href = blobUrl;link.download = '下載文件.mp4';link.click();window.URL.revokeObjectURL(blobUrl);})}</script> </body> </html>?
轉載于:https://www.cnblogs.com/wangrui38/p/11384777.html
總結
- 上一篇: C++、C#、Java、Python、可
- 下一篇: DNF—警告码(0,20003,116)