<el-icon class="operationicon" @click="download(scope.row.file_url)" style="margin:0 0 0 5px;">
<Download />
</el-icon>
<script lang="setup">
const download = (file_url:any) => {
console.log('file_url: ', file_url)
let timestamp = new Date().getTime();
getBlob(file_url).then(blob => {
saveAs(blob, timestamp);
});
}
const getBlob = (url:any) => {
return new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response);
}
};
xhr.send();
});
}
const saveAs = (blob:any, filename:any) => {
var link = document.createElement('a');
let videoFile = new File([blob], filename + ".mp4", {
type: 'video/mp4'
})
link.href = window.URL.createObjectURL(videoFile);
link.download = filename;
link.click();
}
const saveFile = (item:any) => {
console.log('download item: ', item)
var link = document.createElement('a');
link.href = item.file_url;
link.download = 'magic.mp4';
link.click();
}