前端接收流数据并下载

126 阅读1分钟

这里只展示了接收视频流并下载成指定文件名的写法:

 fetch(VideoUrl)
    .then((res) => res.blob())
    .then((blob) => {      
        const a = document.createElement("a");     
        // 创建Object URL 对象 
        const objectUrl = window.URL.createObjectURL(blob);      
        a.download = (item.title || '视频')+'.mp4';      
        a.href = objectUrl;     
        a.click();      
        // 清空内存数据
        window.URL.revokeObjectURL(objectUrl);      
    }).catch(err => {      console.error(err);          });