下載mp4文件


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM