fix: Download button opens URL instead of downloading (#10710)

This commit is contained in:
Sivin Varghese
2025-01-17 14:34:44 +05:30
committed by GitHub
parent f2ff3b42e3
commit 3da97d97be
5 changed files with 16 additions and 32 deletions

View File

@@ -2,6 +2,7 @@
import { computed, onMounted, useTemplateRef, ref } from 'vue';
import Icon from 'next/icon/Icon.vue';
import { timeStampAppendedURL } from 'dashboard/helper/URLHelper';
import { downloadFile } from '@chatwoot/utils';
const { attachment } = defineProps({
attachment: {
@@ -73,17 +74,8 @@ const onEnd = () => {
};
const downloadAudio = async () => {
const response = await fetch(timeStampURL.value);
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = url;
const filename = timeStampURL.value.split('/').pop().split('?')[0] || 'audio';
anchor.download = filename;
document.body.appendChild(anchor);
anchor.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(anchor);
const { fileType, dataUrl, extension } = attachment;
downloadFile({ url: dataUrl, type: fileType, extension });
};
</script>