2020-09-23 17:15:09 +02:00
|
|
|
<script>
|
2020-09-24 16:50:51 +02:00
|
|
|
import { Heading, Body, Button, Dropzone } from "@budibase/bbui"
|
2020-09-23 17:15:09 +02:00
|
|
|
import { FILE_TYPES } from "./fileTypes"
|
|
|
|
|
|
|
|
const BYTES_IN_KB = 1000
|
|
|
|
|
|
|
|
export let files = []
|
|
|
|
|
2020-09-24 16:50:51 +02:00
|
|
|
function handleFileTooLarge(fileSizeLimit) {
|
|
|
|
alert(
|
|
|
|
`Files cannot exceed ${fileSizeLimit /
|
|
|
|
BYTES_IN_MB}MB. Please try again with smaller files.`
|
|
|
|
)
|
2020-09-23 17:15:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function processFiles(fileList) {
|
|
|
|
let data = new FormData()
|
|
|
|
for (var i = 0; i < fileList.length; i++) {
|
|
|
|
data.append("file", fileList[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await fetch("/api/attachments/upload", {
|
|
|
|
method: "POST",
|
|
|
|
body: data,
|
|
|
|
headers: {
|
|
|
|
Accept: "application/json",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const processedFiles = await response.json()
|
2020-09-24 16:50:51 +02:00
|
|
|
return processedFiles
|
2020-09-23 17:15:09 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2020-09-24 16:50:51 +02:00
|
|
|
<Dropzone bind:files {processFiles} {handleFileTooLarge} />
|