fix(custom-request): unable to download utf-8 encoded files (#6541)

This commit is contained in:
YANG QIA 2025-03-24 17:18:14 +08:00 committed by GitHub
parent 38bac8291e
commit 3b86eccca4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;