From 3c28fd3c74d77891d7b2dab124798718de842cf9 Mon Sep 17 00:00:00 2001 From: Georg Spar Date: Sat, 24 Jun 2023 00:45:16 +0200 Subject: [PATCH] update Photo form-data --- wdm.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/wdm.go b/wdm.go index 73aae40..4efea18 100644 --- a/wdm.go +++ b/wdm.go @@ -343,12 +343,26 @@ func updatePhotoHandler(writer http.ResponseWriter, req *http.Request) { if req.Method == http.MethodOptions { return } - body, err := io.ReadAll(req.Body) + + err := req.ParseMultipartForm(64 << 20) if err != nil { writer.WriteHeader(http.StatusBadRequest) + return } var pho Photos - json.Unmarshal(body, &pho) + if req.Form["pfad"] != nil { + pho.Id, _ = strconv.ParseUint(req.FormValue("id"), 10, 0) + pho.Pfad = req.FormValue("pfad") + pho.ItembId, _ = strconv.ParseUint(req.FormValue("itembid"), 10, 0) + pho.ItemextId, _ = strconv.ParseUint(req.FormValue("itemextid"), 10, 0) + } else { + body, err := io.ReadAll(req.Body) + if err != nil { + writer.WriteHeader(http.StatusBadRequest) + } + var pho Photos + json.Unmarshal(body, &pho) + } log.Println("Name = ", pho.Pfad) log.Info("updating Photo", pho.Pfad) res, err := UpdatePhoto(pho)