multipart form correct destroying.

This commit is contained in:
Miroslav Šedivý 2021-01-14 19:54:22 +01:00
parent a96b770052
commit 8c47cbae68

View File

@ -19,6 +19,13 @@ const (
func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(MAX_UPLOAD_SIZE)
if r.MultipartForm == nil {
utils.HttpBadRequest(w, "No MultipartForm received.")
return
}
defer r.MultipartForm.RemoveAll()
X, err := strconv.Atoi(r.FormValue("x"))
if err != nil {
utils.HttpBadRequest(w, "No X coordinate received.")
@ -31,11 +38,6 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) {
return
}
if r.MultipartForm == nil {
utils.HttpBadRequest(w, "No MultipartForm received.")
return
}
req_files := r.MultipartForm.File["files"]
if len(req_files) == 0 {
utils.HttpBadRequest(w, "No files received.")
@ -77,8 +79,10 @@ func (h *RoomHandler) uploadDrop(w http.ResponseWriter, r *http.Request) {
files = append(files, path)
}
h.desktop.DropFiles(X, Y, files)
if !h.desktop.DropFiles(X, Y, files) {
utils.HttpInternalServerError(w, "Unable to drop files.")
return
}
r.MultipartForm.RemoveAll()
utils.HttpSuccess(w)
}