fix: Download button opens URL instead of downloading (#10710)
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user