From 5dea945f68aa55ff9fd76a54c7c2ae9b1631a1c4 Mon Sep 17 00:00:00 2001 From: Georg Spar Date: Thu, 22 Jun 2023 21:22:41 +0200 Subject: [PATCH] json nicht form-data --- data.go | 9 +++++++++ wdm.go | 31 ++++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/data.go b/data.go index 44497ef..0579cf7 100644 --- a/data.go +++ b/data.go @@ -91,3 +91,12 @@ type ItemExt struct { ItemBId uint64 `json:"itembid"` Frontview Photos `json:"frontview"` } + +// Upload-struct + +type ImgUpload struct { + ObjUrl string `json:"objectURL"` + Name string `json:"name"` + Size int `json:"size"` + Type string `json:"type"` +} diff --git a/wdm.go b/wdm.go index 775fecc..b25f5fb 100644 --- a/wdm.go +++ b/wdm.go @@ -713,7 +713,7 @@ func uploadFileHandler(writer http.ResponseWriter, req *http.Request) { return } - err := req.ParseMultipartForm(64 << 20) + /*err := req.ParseMultipartForm(64 << 20) if err != nil { writer.WriteHeader(http.StatusBadRequest) return @@ -748,14 +748,15 @@ func uploadFileHandler(writer http.ResponseWriter, req *http.Request) { } - } else { - body, err := io.ReadAll(req.Body) - if err != nil { - writer.WriteHeader(http.StatusBadRequest) - } - var pho []Photos - json.Unmarshal(body, &pho) + } else {*/ + body, err := io.ReadAll(req.Body) + if err != nil { + writer.WriteHeader(http.StatusBadRequest) } + var pho ImgUpload + //var pho []Photos + json.Unmarshal(body, &pho) + /*} if len(pho) == 0 { log.Fatal("Error: Size of Array = 0") writer.WriteHeader(http.StatusInternalServerError) @@ -773,12 +774,12 @@ func uploadFileHandler(writer http.ResponseWriter, req *http.Request) { b, err := json.Marshal(res) if err != nil { log.Fatal("Error: ", err) - } - location := fmt.Sprintf("%s/%d", req.URL.String(), res.Id) - writer.Header().Set("Location:", location) - writer.Header().Set("Content-Type", "application/json") - writer.WriteHeader(http.StatusCreated) - writer.Write(b) - } + }*/ + location := fmt.Sprintf("%s", req.URL.String()) + writer.Header().Set("Location:", location) + writer.Header().Set("Content-Type", "application/json") + writer.WriteHeader(http.StatusCreated) + writer.Write(b) + //} }