From 3b86eccca4d0aa83d4e3c03bfbd7de9536c77b63 Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Mon, 24 Mar 2025 17:18:14 +0800 Subject: [PATCH] fix(custom-request): unable to download utf-8 encoded files (#6541) --- .../client/hooks/useCustomizeRequestActionProps.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-action-custom-request/src/client/hooks/useCustomizeRequestActionProps.ts b/packages/plugins/@nocobase/plugin-action-custom-request/src/client/hooks/useCustomizeRequestActionProps.ts index 4e8754e313..e64d9e41d7 100644 --- a/packages/plugins/@nocobase/plugin-action-custom-request/src/client/hooks/useCustomizeRequestActionProps.ts +++ b/packages/plugins/@nocobase/plugin-action-custom-request/src/client/hooks/useCustomizeRequestActionProps.ts @@ -67,10 +67,13 @@ export const useCustomizeRequestActionProps = () => { responseType: fieldSchema['x-response-type'] === 'stream' ? 'blob' : 'json', }); if (res.headers['content-disposition']) { - const regex = /attachment;\s*filename="([^"]+)"/; - const match = res.headers['content-disposition'].match(regex); - if (match?.[1]) { - saveAs(res.data, match[1]); + const contentDisposition = res.headers['content-disposition']; + const utf8Match = contentDisposition.match(/filename\*=utf-8''([^;]+)/i); + const asciiMatch = contentDisposition.match(/filename="([^"]+)"/i); + if (utf8Match) { + saveAs(res.data, decodeURIComponent(utf8Match[1])); + } else if (asciiMatch) { + saveAs(res.data, asciiMatch[1]); } } actionField.data.loading = false;