diff --git a/packages/bbui/src/Form/Core/Dropzone.svelte b/packages/bbui/src/Form/Core/Dropzone.svelte index 5b5c72b809..3315c923f8 100644 --- a/packages/bbui/src/Form/Core/Dropzone.svelte +++ b/packages/bbui/src/Form/Core/Dropzone.svelte @@ -37,9 +37,28 @@ const fieldId = id || generateID() let selectedImageIdx = 0 let fileDragged = false + let selectedUrl $: selectedImage = value?.[selectedImageIdx] ?? null $: fileCount = value?.length ?? 0 - $: isImage = imageExtensions.includes(selectedImage?.extension?.toLowerCase()) + $: isImage = + imageExtensions.includes(selectedImage?.extension?.toLowerCase()) || + selectedImage?.type?.startsWith("image") + + $: { + if (selectedImage?.url) { + selectedUrl = selectedImage?.url + } else if (selectedImage) { + try { + let reader = new FileReader() + reader.readAsDataURL(selectedImage) + reader.onload = e => { + selectedUrl = e.target.result + } + } catch (error) { + selectedUrl = null + } + } + } async function processFileList(fileList) { if ( @@ -102,11 +121,13 @@