fix: Preview for local Files #4
continuous-integration/drone/push Build is passing Details

main
Flycro 2024-03-21 12:36:24 +01:00
parent 9fd7b9f4c3
commit 78e3f0ff0c
1 changed files with 5 additions and 1 deletions

View File

@ -118,6 +118,10 @@ async function onSubmit(event: FormSubmitEvent<any>) {
function isFile(value: any): value is File { function isFile(value: any): value is File {
return value instanceof File return value instanceof File
} }
function getFileUrl(file: File) {
return URL.createObjectURL(file)
}
</script> </script>
<template> <template>
@ -150,7 +154,7 @@ function isFile(value: any): value is File {
</UFormGroup> </UFormGroup>
<img v-if="state.cover_image && typeof state.cover_image === 'string'" :src="$storage(state.cover_image)" alt="Cover" class="size-1/3 content-center rounded-lg"> <img v-if="state.cover_image && typeof state.cover_image === 'string'" :src="$storage(state.cover_image)" alt="Cover" class="size-1/3 content-center rounded-lg">
<ClientOnly> <ClientOnly>
<img v-if="state.cover_image && isFile(state.cover_image)" :src="URL.createObjectURL(state.cover_image)" alt="Cover" class="size-1/3 content-center rounded-lg"> <img v-if="state.cover_image && isFile(state.cover_image)" :src="getFileUrl(state.cover_image)" alt="Cover" class="size-1/3 content-center rounded-lg">
</ClientOnly>> </ClientOnly>>
<UFormGroup label="Cover" name="cover_image"> <UFormGroup label="Cover" name="cover_image">
<UInput type="file" @change="handleCoverImageInput" /> <UInput type="file" @change="handleCoverImageInput" />