From f938723d9a652592419823cf1de5c5bd7958df5f Mon Sep 17 00:00:00 2001 From: Ivan Shelepugin Date: Mon, 1 Dec 2025 00:58:40 +0300 Subject: [PATCH] fix(api): correct values of `Content-Disposition` attributes (#260) --- apps/web/src/pages/api/download/attatchment.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/web/src/pages/api/download/attatchment.ts b/apps/web/src/pages/api/download/attatchment.ts index 2c82e54f..d174565e 100644 --- a/apps/web/src/pages/api/download/attatchment.ts +++ b/apps/web/src/pages/api/download/attatchment.ts @@ -17,12 +17,11 @@ export default async function handler( } try { - const downloadUrl = decodeURIComponent(url); - const downloadFilename = - (typeof filename === "string" ? decodeURIComponent(filename) : null) ?? - "attachment"; + const downloadFilename = typeof filename === "string" + ? encodeURIComponent(filename) + : "attachment"; - const upstream = await fetch(downloadUrl); + const upstream = await fetch(url); if (!upstream.ok) { return res.status(upstream.status).json({ @@ -36,7 +35,7 @@ export default async function handler( res.setHeader("Content-Type", contentType); res.setHeader( "Content-Disposition", - `attachment; filename="${downloadFilename}"`, + `attachment; filename="${downloadFilename}"; filename*=UTF-8''${downloadFilename}`, ); const buffer = await upstream.arrayBuffer();