budibase/packages/standard-components/src/attachments/Dropzone.svelte

26 lines
627 B
Svelte
Raw Normal View History

2020-09-23 17:15:09 +02:00
<script>
2020-11-11 15:26:33 +01:00
import { Dropzone } from "@budibase/bbui"
import { uploadAttachment } from "@budibase/component-sdk"
2020-09-23 17:15:09 +02:00
const BYTES_IN_MB = 1000000
2020-09-23 17:15:09 +02:00
export let files = []
2020-09-24 16:50:51 +02:00
function handleFileTooLarge(fileSizeLimit) {
alert(
2020-10-27 16:28:13 +01:00
`Files cannot exceed ${fileSizeLimit /
BYTES_IN_MB}MB. Please try again with smaller files.`
2020-09-24 16:50:51 +02:00
)
2020-09-23 17:15:09 +02:00
}
async function processFiles(fileList) {
let data = new FormData()
2020-11-11 15:26:33 +01:00
for (let i = 0; i < fileList.length; i++) {
2020-09-23 17:15:09 +02:00
data.append("file", fileList[i])
}
return await uploadAttachment(data)
2020-09-23 17:15:09 +02:00
}
</script>
2020-09-24 16:50:51 +02:00
<Dropzone bind:files {processFiles} {handleFileTooLarge} />