From 7520e9d42226edb552b48700b9529a342a57ac47 Mon Sep 17 00:00:00 2001 From: RKWojs Date: Tue, 13 Jan 2026 13:25:05 +0100 Subject: [PATCH] fix: await params in GET request and update Content-Disposition header for special characters --- src/app/api/templates/download/[filename]/route.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/api/templates/download/[filename]/route.js b/src/app/api/templates/download/[filename]/route.js index d75a545..6006f4d 100644 --- a/src/app/api/templates/download/[filename]/route.js +++ b/src/app/api/templates/download/[filename]/route.js @@ -6,7 +6,8 @@ import db from "@/lib/db"; export async function GET(request, { params }) { try { - const { filename } = params; + // Await params (Next.js 15+ requirement) + const { filename } = await params; if (!filename) { return NextResponse.json( @@ -39,12 +40,16 @@ export async function GET(request, { params }) { // Read file const fileBuffer = await readFile(filePath); + // Encode filename for Content-Disposition header (RFC 5987) + // This handles Polish and other special characters + const encodedFilename = encodeURIComponent(template.original_filename); + // Return file with proper headers const response = new NextResponse(fileBuffer, { status: 200, headers: { "Content-Type": template.mime_type || "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - "Content-Disposition": `attachment; filename="${template.original_filename}"`, + "Content-Disposition": `attachment; filename*=UTF-8''${encodedFilename}`, "Content-Length": fileBuffer.length.toString(), }, });