Browse Source

json nicht form-data

pull/1/head
Georg Spar 1 year ago
parent
commit
5dea945f68
  1. 9
      data.go
  2. 31
      wdm.go

9
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"`
}

31
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)
//}
}

Loading…
Cancel
Save