1
0
Fork 0
mirror of synced 2024-08-04 12:51:47 +12:00
budibase/packages/standard-components/src/attachments/Dropzone.svelte

36 lines
837 B
Svelte
Raw Normal View History

2020-09-24 03:15:09 +12:00
<script>
2020-09-25 02:50:51 +12:00
import { Heading, Body, Button, Dropzone } from "@budibase/bbui"
2020-09-24 03:15:09 +12:00
import { FILE_TYPES } from "./fileTypes"
const BYTES_IN_KB = 1000
export let files = []
2020-09-25 02:50:51 +12:00
function handleFileTooLarge(fileSizeLimit) {
alert(
`Files cannot exceed ${fileSizeLimit /
BYTES_IN_MB}MB. Please try again with smaller files.`
)
2020-09-24 03:15:09 +12: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-25 02:50:51 +12:00
return processedFiles
2020-09-24 03:15:09 +12:00
}
</script>
2020-09-25 02:50:51 +12:00
<Dropzone bind:files {processFiles} {handleFileTooLarge} />