Fix file downloads for Safari with proper filename handling

Implement browser-specific download methods to ensure files download with correct filenames across all browsers. Safari now uses window.location.href while other browsers use blob URLs. Add Content-Disposition header to proxy endpoint for proper filename preservation.
This commit is contained in:
2025-06-04 19:13:09 +02:00
parent b7544d82f3
commit 4d3935e863
3 changed files with 74 additions and 34 deletions

View File

@@ -41,7 +41,8 @@ export default defineEventHandler(async (event) => {
// Set headers for download
setHeader(event, 'Content-Type', contentType);
setHeader(event, 'Content-Disposition', `attachment; filename="${cleanFileName}"`);
// Use both filename and filename* for better compatibility
setHeader(event, 'Content-Disposition', `attachment; filename="${cleanFileName}"; filename*=UTF-8''${encodeURIComponent(cleanFileName)}`);
// Content-Length header is set automatically by Nitro when returning a buffer
// Return the file buffer