zoukankan      html  css  js  c++  java
  • 下载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>
  • 相关阅读:
    无线桥接(WDS)如何设置?
    Linux内核的整体架构简介
    Efuse--芯片存储
    Linux下编写和加载 .ko 文件(驱动模块文件)
    统计难题
    最少拦截系统
    (比赛)B
    (比赛)A
    F
    K
  • 原文地址:https://www.cnblogs.com/wangrui38/p/11384777.html
Copyright © 2011-2022 走看看