diff --git a/packages/frontend-core/src/utils/download.js b/packages/frontend-core/src/utils/download.js index b887122969..55ba899ee6 100644 --- a/packages/frontend-core/src/utils/download.js +++ b/packages/frontend-core/src/utils/download.js @@ -46,23 +46,23 @@ export async function downloadFile(url, body) { if (!response.ok) { return false + } else { + const contentDisposition = response.headers.get("Content-Disposition") + + const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec( + contentDisposition + ) + + const filename = matches[1].replace(/['"]/g, "") + + const url = URL.createObjectURL(await response.blob()) + + const link = document.createElement("a") + link.href = url + link.download = filename + link.click() + + URL.revokeObjectURL(url) + return true } - - const contentDisposition = response.headers.get("Content-Disposition") - - const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec( - contentDisposition - ) - - const filename = matches[1].replace(/['"]/g, "") - - const url = URL.createObjectURL(await response.blob()) - - const link = document.createElement("a") - link.href = url - link.download = filename - link.click() - - URL.revokeObjectURL(url) - return true }