这是平时在实际开发中所总结出来的,不管难易,只希望和各位交流一下技术,分享一些东西,
共同进步,有什么更好的优化或者有问题欢迎评论区留言,大家帮帮点点赞哦
//下载
const clickUpload = async (id) => {
let params = {
id: id,
}
const res = await uploadFile(params)
console.log(res)
downloadVideo(res.data)
}
const downloadVideo = (url) => {
fetch(url).then(function (response) {
response.arrayBuffer().then((res) => {
let type = 'video/*'
/* 常见资源类型
1.excel: type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
2.图片: type = "image/*"
3.视频: type = "video/*"
4.音频: type = "audio/*"
*/
let blob = new Blob([res], { type: type })
// 获取的blob根据实际业务场景应用下载,或转化成其他格式的资源
var objectUrl = URL.createObjectURL(blob)
var a = document.createElement('a')
document.body.appendChild(a)
a.style.display = 'none'
a.href = objectUrl
a.setAttribute('download', '视频.mp4')
a.click()
document.body.removeChild(a)
})
})
}