fix: Changed image extension validation to MIME type validation

This commit is contained in:
Joedeep Singh
2025-07-03 20:17:41 +00:00
parent f2c8788602
commit 5f04607a44
3 changed files with 14 additions and 11 deletions

View File

@@ -209,7 +209,7 @@
v-slot="{ file, progress, uploading, openFileSelector }" v-slot="{ file, progress, uploading, openFileSelector }"
> >
<div class="flex items-center"> <div class="flex items-center">
<div class="border rounded-md w-fit py-5 px-20"> <div class="border rounded-md w-fit py-5 px-20 cursor-pointer" @click="openFileSelector">
<Image class="size-5 stroke-1 text-ink-gray-7" /> <Image class="size-5 stroke-1 text-ink-gray-7" />
</div> </div>
<div class="ml-4"> <div class="ml-4">
@@ -540,9 +540,10 @@ const removeImage = () => {
} }
const validateFile = (file) => { const validateFile = (file) => {
let extension = file.name.split('.').pop().toLowerCase() if (!file.type.startsWith('image/')) {
if (!['jpg', 'jpeg', 'png'].includes(extension)) { const errorMessage = __('Only image file is allowed.')
return 'Only image file is allowed.' toast.error(errorMessage)
return errorMessage
} }
} }

View File

@@ -100,7 +100,7 @@
v-slot="{ file, progress, uploading, openFileSelector }" v-slot="{ file, progress, uploading, openFileSelector }"
> >
<div class="flex items-center"> <div class="flex items-center">
<div class="border rounded-md w-fit py-5 px-20"> <div class="border rounded-md w-fit py-5 px-20 cursor-pointer" @click="openFileSelector">
<Image class="size-5 stroke-1 text-ink-gray-7" /> <Image class="size-5 stroke-1 text-ink-gray-7" />
</div> </div>
<div class="ml-4"> <div class="ml-4">
@@ -592,9 +592,10 @@ watch(
) )
const validateFile = (file) => { const validateFile = (file) => {
let extension = file.name.split('.').pop().toLowerCase() if (!file.type.startsWith('image/')) {
if (!['jpg', 'jpeg', 'png', 'webp'].includes(extension)) { const errorMessage = __('Only image file is allowed.')
return __('Only image file is allowed.') toast.error(errorMessage)
return errorMessage
} }
} }

View File

@@ -294,9 +294,10 @@ const removeImage = () => {
} }
const validateFile = (file) => { const validateFile = (file) => {
let extension = file.name.split('.').pop().toLowerCase() if (!file.type.startsWith('image/')) {
if (!['jpg', 'jpeg', 'png'].includes(extension)) { const errorMessage = __('Only image file is allowed.')
return 'Only image file is allowed.' toast.error(errorMessage)
return errorMessage
} }
} }