fixing attachments for public apps

This commit is contained in:
Martin McKeaveney 2021-06-08 12:50:58 +01:00
parent 7f934327b7
commit 499583ff22
4 changed files with 12 additions and 8 deletions

View File

@ -3,9 +3,9 @@ import API from "./api"
/** /**
* Uploads an attachment to the server. * Uploads an attachment to the server.
*/ */
export const uploadAttachment = async data => { export const uploadAttachment = async (data, tableId = "") => {
return await API.post({ return await API.post({
url: "/api/attachments/upload", url: `/api/attachments/${tableId}/upload`,
body: data, body: data,
json: false, json: false,
}) })

View File

@ -7,8 +7,8 @@ const {
PermissionTypes, PermissionTypes,
PermissionLevels, PermissionLevels,
} = require("@budibase/auth/permissions") } = require("@budibase/auth/permissions")
const usage = require("../../middleware/usageQuota")
const env = require("../../environment") const env = require("../../environment")
const { paramResource } = require("../../middleware/resourceId")
const router = Router() const router = Router()
@ -39,9 +39,9 @@ router
.get("/builder/:file*", controller.serveBuilder) .get("/builder/:file*", controller.serveBuilder)
.post("/api/attachments/process", authorized(BUILDER), controller.uploadFile) .post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
.post( .post(
"/api/attachments/upload", "/api/attachments/:tableId/upload",
paramResource("tableId"),
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
usage,
controller.uploadFile controller.uploadFile
) )
.get("/componentlibrary", controller.serveComponentLibrary) .get("/componentlibrary", controller.serveComponentLibrary)

View File

@ -9,8 +9,10 @@
let fieldState let fieldState
let fieldApi let fieldApi
let fieldSchema
const { API, notifications } = getContext("sdk") const { API, notifications } = getContext("sdk")
const formContext = getContext("form")
const BYTES_IN_MB = 1000000 const BYTES_IN_MB = 1000000
export let files = [] export let files = []
@ -28,7 +30,7 @@
for (let i = 0; i < fileList.length; i++) { for (let i = 0; i < fileList.length; i++) {
data.append("file", fileList[i]) data.append("file", fileList[i])
} }
return await API.uploadAttachment(data) return await API.uploadAttachment(data, formContext?.dataSource?.tableId)
} }
</script> </script>
@ -45,7 +47,9 @@
<CoreDropzone <CoreDropzone
value={$fieldState.value} value={$fieldState.value}
disabled={$fieldState.disabled} disabled={$fieldState.disabled}
on:change={e => fieldApi.setValue(e.detail)} on:change={e => {
fieldApi.setValue(e.detail)
}}
{processFiles} {processFiles}
{handleFileTooLarge} {handleFileTooLarge}
/> />

View File

@ -80,7 +80,7 @@
} }
// Provide both form API and state to children // Provide both form API and state to children
setContext("form", { formApi, formState }) setContext("form", { formApi, formState, dataSource })
// Action context to pass to children // Action context to pass to children
$: actions = [{ type: ActionTypes.ValidateForm, callback: formApi.validate }] $: actions = [{ type: ActionTypes.ValidateForm, callback: formApi.validate }]