Browse Source

erneuter Umbau auf form-data

pull/1/head
Georg Spar 1 year ago
parent
commit
307dcd2d12
  1. 23
      wdm.go

23
wdm.go

@ -713,7 +713,7 @@ func uploadFileHandler(writer http.ResponseWriter, req *http.Request) {
return return
} }
/*err := req.ParseMultipartForm(64 << 20) err := req.ParseMultipartForm(64 << 20)
if err != nil { if err != nil {
writer.WriteHeader(http.StatusBadRequest) writer.WriteHeader(http.StatusBadRequest)
return return
@ -725,10 +725,10 @@ func uploadFileHandler(writer http.ResponseWriter, req *http.Request) {
} }
if req.Form["files"] != nil { if req.Form["files"] != nil {
for i := 0; i < len(req.Form["files"]); i++ { for i := 0; i < len(req.Form["file"]); i++ {
log.Info("File-Name:", req.FormValue("files.File.name")) log.Info("File-Name:", req.FormValue("file.name"))
file, handler, err := req.FormFile("files.File") file, handler, err := req.FormFile("file")
if err != nil { if err != nil {
panic(err) //dont do this panic(err) //dont do this
} }
@ -748,16 +748,7 @@ func uploadFileHandler(writer http.ResponseWriter, req *http.Request) {
} }
} else {*/
body, err := io.ReadAll(req.Body)
if err != nil {
writer.WriteHeader(http.StatusBadRequest)
} }
var pho []ImgUpload
//var pho []Photos
json.Unmarshal(body, &pho)
log.Info("objURL: ", pho[0].ObjUrl)
/*}
if len(pho) == 0 { if len(pho) == 0 {
log.Fatal("Error: Size of Array = 0") log.Fatal("Error: Size of Array = 0")
writer.WriteHeader(http.StatusInternalServerError) writer.WriteHeader(http.StatusInternalServerError)
@ -775,12 +766,12 @@ func uploadFileHandler(writer http.ResponseWriter, req *http.Request) {
b, err := json.Marshal(res) b, err := json.Marshal(res)
if err != nil { if err != nil {
log.Fatal("Error: ", err) log.Fatal("Error: ", err)
}*/ }
location := fmt.Sprintf("%s", req.URL.String()) location := fmt.Sprintf("%s", req.URL.String())
writer.Header().Set("Location:", location) writer.Header().Set("Location:", location)
writer.Header().Set("Content-Type", "application/json") writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusCreated) writer.WriteHeader(http.StatusCreated)
//writer.Write(b) writer.Write(b)
//} }
} }

Loading…
Cancel
Save