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.
This commit is contained in:
Matt 2025-06-04 18:29:52 +02:00
parent 482af0c862
commit 1463fdb3d7
2 changed files with 30 additions and 3 deletions

View File

@ -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);
}

View File

@ -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 {