Download attachment api (returns only first for now)
This commit is contained in:
parent
94eefb8007
commit
d91da45880
|
@ -1,4 +1,5 @@
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
|
import { objectStore } from "@budibase/backend-core"
|
||||||
import * as internal from "./internal"
|
import * as internal from "./internal"
|
||||||
import * as external from "./external"
|
import * as external from "./external"
|
||||||
import { isExternalTableID } from "../../../integrations/utils"
|
import { isExternalTableID } from "../../../integrations/utils"
|
||||||
|
@ -13,6 +14,7 @@ import {
|
||||||
PatchRowRequest,
|
PatchRowRequest,
|
||||||
PatchRowResponse,
|
PatchRowResponse,
|
||||||
Row,
|
Row,
|
||||||
|
RowAttachment,
|
||||||
SearchParams,
|
SearchParams,
|
||||||
SearchRowRequest,
|
SearchRowRequest,
|
||||||
SearchRowResponse,
|
SearchRowResponse,
|
||||||
|
@ -251,3 +253,21 @@ export const exportRows = async (
|
||||||
ctx.attachment(fileName)
|
ctx.attachment(fileName)
|
||||||
ctx.body = apiFileReturn(content)
|
ctx.body = apiFileReturn(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function downloadAttachment(ctx: UserCtx) {
|
||||||
|
const { columnName } = ctx.params
|
||||||
|
|
||||||
|
const tableId = utils.getTableId(ctx)
|
||||||
|
const row = await pickApi(tableId).find(ctx)
|
||||||
|
|
||||||
|
if (!row[columnName]) {
|
||||||
|
ctx.throw(400, `'${columnName}' is not valid`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const attachment: RowAttachment = row[columnName][0]
|
||||||
|
ctx.attachment(attachment.name)
|
||||||
|
ctx.body = await objectStore.getReadStream(
|
||||||
|
objectStore.ObjectStoreBuckets.APPS,
|
||||||
|
attachment.key
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,12 @@ router
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
||||||
rowController.exportRows
|
rowController.exportRows
|
||||||
)
|
)
|
||||||
|
.get(
|
||||||
|
"/api/:sourceId/rows/:rowId/attachment/:columnName",
|
||||||
|
paramSubResource("sourceId", "rowId"),
|
||||||
|
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
||||||
|
rowController.downloadAttachment
|
||||||
|
)
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/api/v2/views/:viewId/search",
|
"/api/v2/views/:viewId/search",
|
||||||
|
|
Loading…
Reference in New Issue