From 8c47cbae688bf582280d5bbe34aae71df4b31706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 14 Jan 2021 19:54:22 +0100 Subject: [PATCH] multipart form correct destroying. --- internal/api/room/upload.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/api/room/upload.go b/internal/api/room/upload.go index acb6bc0f..e98d5ff3 100644 --- a/internal/api/room/upload.go +++ b/internal/api/room/upload.go @@ -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) }