diff --git a/packages/frontend-core/src/api/attachments.js b/packages/frontend-core/src/api/attachments.js index c2ac5c369c..cff466c86f 100644 --- a/packages/frontend-core/src/api/attachments.js +++ b/packages/frontend-core/src/api/attachments.js @@ -91,13 +91,13 @@ export const buildAttachmentEndpoints = API => { /** * Download an attachment from a row given its column name. - * @param tableId - * @param rowId - * @param columnName the attachments to delete + * @param datasourceId the ID of the datasource to download from + * @param rowId the ID of the row to download from + * @param columnName the column name to download */ - downloadAttachment: async (tableId, rowId, columnName, options) => { + downloadAttachment: async (datasourceId, rowId, columnName, options) => { return await API.get({ - url: `/api/${tableId}/rows/${rowId}/attachment/${columnName}`, + url: `/api/${datasourceId}/rows/${rowId}/attachment/${columnName}`, parseResponse: response => response, suppressErrors: options?.suppressErrors, }) diff --git a/packages/frontend-core/src/utils/download.js b/packages/frontend-core/src/utils/download.js index 55ba899ee6..fb9990ff30 100644 --- a/packages/frontend-core/src/utils/download.js +++ b/packages/frontend-core/src/utils/download.js @@ -1,3 +1,5 @@ +const extractFileNameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/ + export function downloadText(filename, text) { if (typeof text === "object") { text = JSON.stringify(text) @@ -17,9 +19,7 @@ export async function downloadStream(streamResponse) { const contentDisposition = streamResponse.headers.get("Content-Disposition") - const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec( - contentDisposition - ) + const matches = extractFileNameRegex.exec(contentDisposition) const filename = matches[1].replace(/['"]/g, "") @@ -49,9 +49,7 @@ export async function downloadFile(url, body) { } else { const contentDisposition = response.headers.get("Content-Disposition") - const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec( - contentDisposition - ) + const matches = extractFileNameRegex.exec(contentDisposition) const filename = matches[1].replace(/['"]/g, "")