From 1463fdb3d778b156f14b42f8f9aa56fb5dd369cf Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 4 Jun 2025 18:29:52 +0200 Subject: [PATCH] Fix file download for mobile Safari compatibility Replace window.open() with programmatic link creation and click to ensure file downloads work properly on mobile Safari. Also adds proper filename handling to preserve extensions during download. --- components/FilePreviewModal.vue | 16 +++++++++++++++- pages/dashboard/file-browser.vue | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/components/FilePreviewModal.vue b/components/FilePreviewModal.vue index b2e12ba..78761d9 100644 --- a/components/FilePreviewModal.vue +++ b/components/FilePreviewModal.vue @@ -208,7 +208,21 @@ const downloadFile = async () => { params: { fileName: props.file.name }, }); - window.open(response.url, '_blank'); + // For mobile Safari, we need to use a different approach + const link = document.createElement('a'); + link.href = response.url; + link.target = '_blank'; + + // Extract clean filename for download + let filename = props.file.displayName; + if (!filename.includes('.') && props.file.extension) { + filename += '.' + props.file.extension; + } + + link.download = filename; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); } catch (err) { console.error('Failed to download file:', err); } diff --git a/pages/dashboard/file-browser.vue b/pages/dashboard/file-browser.vue index 954a173..ae7ade4 100644 --- a/pages/dashboard/file-browser.vue +++ b/pages/dashboard/file-browser.vue @@ -469,8 +469,21 @@ const downloadFile = async (file: FileItem) => { params: { fileName: file.name }, }); - // Open download URL in new tab - window.open(response.url, '_blank'); + // For mobile Safari compatibility, use a link element + const link = document.createElement('a'); + link.href = response.url; + link.target = '_blank'; + + // Extract clean filename for download + let filename = file.displayName; + if (!filename.includes('.') && file.extension) { + filename += '.' + file.extension; + } + + link.download = filename; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); } catch (error) { toast.error('Failed to generate download link'); } finally {