實現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>