I am developing a web app and having a url like(this is fake):
http://10.100.100.10:1000/a/b/c/000.mp4?a=1&b=2
And my progress is that when I click abc in the page, browser will download the file or bring up windows player to play the video. But when I assign ObjectUrl to tag, it just doesn't work.
Here is my code to download mp4 file. It is based on vue and axiox, but they are not limitation. PS: I use webpack devServer.proxy to solve cors problem but I don't think that's a problem.
<template>
<div @click="mao">abc</div>
<template>
<script>
methods: {
mao: function(){
const vm = this;
const url = "/a/b/c/000.mp4?a=1&b=2";
this.axios({
url,
method: "GET",
responseType: "blob"
})
.then(res => {
const filename = "111.mp4";
const url = URL.createObjectURL(new Blob([res.data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", filename);
link.setAttribute("id", "tmp");
document.body.appendChild(link);
link.click();
return link;
})
.then(link => {
document.body.removeChild(link);
})
}
}
</script>