fix: Add explicit Content-Type and Content-Disposition headers for downloads

Improves browser compatibility for PDF file downloads by setting
proper MIME type and filename encoding.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
richardtekula
2026-01-30 08:42:02 +01:00
parent de327d4d7d
commit 9bc8e2084a

View File

@@ -247,6 +247,11 @@ export const downloadPriloha = async (req, res, next) => {
return res.status(404).json({ success: false, error: { message: 'Súbor nenájdený na serveri' } });
}
// Set explicit headers for better browser compatibility
const mimeType = priloha.mimeType || 'application/octet-stream';
res.setHeader('Content-Type', mimeType);
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(priloha.nazovSuboru)}"`);
res.download(priloha.cestaKSuboru, priloha.nazovSuboru);
} catch (error) {
next(error);