diff --git a/wdm.go b/wdm.go index 7f18e3a..e4ab45a 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 @@ -725,10 +725,10 @@ func uploadFileHandler(writer http.ResponseWriter, req *http.Request) { } if req.Form["files"] != nil { - for i := 0; i < len(req.Form["files"]); i++ { - log.Info("File-Name:", req.FormValue("files.File.name")) + for i := 0; i < len(req.Form["file"]); i++ { + log.Info("File-Name:", req.FormValue("file.name")) - file, handler, err := req.FormFile("files.File") + file, handler, err := req.FormFile("file") if err != nil { 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 { log.Fatal("Error: Size of Array = 0") writer.WriteHeader(http.StatusInternalServerError) @@ -775,12 +766,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", req.URL.String()) - 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) + } }