diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DownloadFile.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DownloadFile.svelte index c8f4ef11f1..babaf2815b 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DownloadFile.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DownloadFile.svelte @@ -35,8 +35,8 @@ parameters.tableId && options.find(t => t.resourceId === parameters.tableId) $: attachmentColumns = selectedTable && - Object.values(selectedTable.schema).filter( - c => c.type === FieldType.ATTACHMENT + Object.values(selectedTable.schema).filter(c => + [FieldType.ATTACHMENTS, FieldType.ATTACHMENT_SINGLE].includes(c.type) ) onMount(() => { diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index b3634922ce..0ff4774e74 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -13,6 +13,7 @@ import { DeleteRows, ExportRowsRequest, ExportRowsResponse, + FieldType, GetRowResponse, PatchRowRequest, PatchRowResponse, @@ -264,11 +265,22 @@ export async function downloadAttachment(ctx: UserCtx) { const row = await pickApi(tableId).find(ctx) const table = await sdk.tables.getTable(tableId) - if (!table.schema[columnName]) { + const columnSchema = table.schema[columnName] + if (!columnSchema) { ctx.throw(400, `'${columnName}' is not valid`) } - const attachments: RowAttachment[] = row[columnName] + const columnType = columnSchema.type + + if ( + columnType !== FieldType.ATTACHMENTS && + columnType !== FieldType.ATTACHMENT_SINGLE + ) { + ctx.throw(404, `'${columnName}' is not valid attachment column`) + } + + const attachments: RowAttachment[] = + columnType === FieldType.ATTACHMENTS ? row[columnName] : [row[columnName]] if (!attachments?.length) { ctx.throw(404)