From 57d096f8b9eaeba3e6b16b24689419e3d5104f86 Mon Sep 17 00:00:00 2001 From: Suraj Date: Tue, 2 Feb 2016 21:08:35 +0530 Subject: [PATCH] Edit Task bug fixed --- views/addViews.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/views/addViews.go b/views/addViews.go index 115759d..32872dd 100644 --- a/views/addViews.go +++ b/views/addViews.go @@ -35,13 +35,15 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { // Will work only for POST requests, will redirect to home r.ParseForm() file, handler, err := r.FormFile("uploadfile") - if err != nil { + if err != nil && handler != nil { + //Case executed when file is uploaded and yet an error occurs log.Println(err) message = "Error uploading file" http.Redirect(w, r, "/", http.StatusInternalServerError) } taskPriority, priorityErr := strconv.Atoi(r.FormValue("priority")) + if priorityErr != nil { log.Print(priorityErr) message = "Bad task priority" @@ -66,6 +68,7 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) { cookie, _ := r.Cookie("csrftoken") if formToken == cookie.Value { if handler != nil { + // this will be executed whenever a file is uploaded r.ParseMultipartForm(32 << 20) //defined maximum size of file defer file.Close() randomFileName := md5.New() @@ -99,8 +102,8 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) { } else { message = "Task added" log.Println("added task to db") + http.Redirect(w, r, "/", http.StatusFound) } - http.Redirect(w, r, "/", http.StatusFound) } else { log.Println("CSRF mismatch") message = "Server Error"