From 781182905d285bd624726ebee91c04add6a1a513 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 29 Nov 2024 14:59:23 +0530 Subject: [PATCH] feat: better download --- .../dashboard/components-next/message/chips/Audio.vue | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/javascript/dashboard/components-next/message/chips/Audio.vue b/app/javascript/dashboard/components-next/message/chips/Audio.vue index d6060d36e..8353ecdeb 100644 --- a/app/javascript/dashboard/components-next/message/chips/Audio.vue +++ b/app/javascript/dashboard/components-next/message/chips/Audio.vue @@ -65,12 +65,17 @@ const onEnd = () => { currentTime.value = 0; }; -const downloadAudio = () => { +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 = timeStampURL.value; - anchor.download = timeStampURL.value.split('/').pop() || 'audio'; + 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); };