From 71e38b982428046c8be8c1b7e1c227377ce118db Mon Sep 17 00:00:00 2001 From: Laurence Jones Date: Wed, 5 Nov 2025 21:03:06 +0000 Subject: [PATCH] Add file type restriction to image upload input using accept attribute (#872) * Add file type restriction to image upload input using accept attribute Signed-off-by: eternal-flame-AD --------- Signed-off-by: eternal-flame-AD Co-authored-by: eternal-flame-AD --- api/application.go | 3 ++- ui/src/application/Applications.tsx | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/application.go b/api/application.go index 805ae2b..6a8ec8e 100644 --- a/api/application.go +++ b/api/application.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "github.com/gin-gonic/gin" "github.com/gotify/server/v2/auth" @@ -459,7 +460,7 @@ func generateNonExistingImageName(imgDir string, gen func() string) string { } func ValidApplicationImageExt(ext string) bool { - switch ext { + switch strings.ToLower(ext) { case ".gif", ".png", ".jpg", ".jpeg": return true default: diff --git a/ui/src/application/Applications.tsx b/ui/src/application/Applications.tsx index e0d2be7..3ceff7e 100644 --- a/ui/src/application/Applications.tsx +++ b/ui/src/application/Applications.tsx @@ -59,6 +59,8 @@ const Applications = observer(() => { useEffect(() => void appStore.refresh(), []); + const validExtensions = ['.gif', '.png', '.jpg', '.jpeg']; + const handleImageUploadClick = (id: number) => { uploadId.current = id; if (fileInputRef.current) { @@ -71,11 +73,7 @@ const Applications = observer(() => { if (!file) { return; } - if (['image/png', 'image/jpeg', 'image/gif'].indexOf(file.type) !== -1) { - appStore.uploadImage(uploadId.current, file); - } else { - alert('Uploaded file must be of type png, jpeg or gif.'); - } + appStore.uploadImage(uploadId.current, file); }; return ( @@ -128,6 +126,7 @@ const Applications = observer(() => {