From 6624c5a989d2e3b700ebeb17af662d4736a01a79 Mon Sep 17 00:00:00 2001 From: Simon Rieger Date: Mon, 2 Sep 2024 15:14:52 +0200 Subject: [PATCH] add force_upload to mimetype detection back again --- go/main.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/go/main.go b/go/main.go index a6ba6ed..c2bc510 100644 --- a/go/main.go +++ b/go/main.go @@ -144,11 +144,14 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { return } - mimeType := http.DetectContentType(buffer) - if !strings.HasPrefix(mimeType, "image/") && !strings.HasPrefix(mimeType, "text/xml") && !strings.HasPrefix(mimeType, "image/svg+xml") { - http.Error(w, "Nur Bild-Uploads sind erlaubt", http.StatusBadRequest) - log.Printf("Versuch, eine Nicht-Bild-Datei hochzuladen: %v", mimeType) - return + forceUpload := r.FormValue("force_upload") + if forceUpload != "true" { + mimeType := http.DetectContentType(buffer) + if !strings.HasPrefix(mimeType, "image/") && !strings.HasPrefix(mimeType, "text/xml") && !strings.HasPrefix(mimeType, "image/svg+xml") { + http.Error(w, "Nur Bild-Uploads sind erlaubt", http.StatusBadRequest) + log.Printf("Versuch, eine Nicht-Bild-Datei hochzuladen: %v", mimeType) + return + } } _, err = file.Seek(0, io.SeekStart) @@ -158,7 +161,6 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { return } - forceUpload := r.FormValue("force_upload") forceName := r.FormValue("force_name") var filename string