diff --git a/list.go b/list.go index 3b55d0a..db3f3de 100644 --- a/list.go +++ b/list.go @@ -122,8 +122,8 @@ func ListFiles(w http.ResponseWriter, r *http.Request) { data := struct { Username string - Files []File SuccessMessage string + Files []File }{ Username: name, Files: files, @@ -189,7 +189,6 @@ func UploadFile(w http.ResponseWriter, r *http.Request) { http.Error(w, "Internal Server Error", http.StatusInternalServerError) return } - defer destFile.Close() _, err = io.Copy(destFile, part) if err != nil { @@ -197,18 +196,19 @@ func UploadFile(w http.ResponseWriter, r *http.Request) { http.Error(w, "Internal Server Error", http.StatusInternalServerError) return } + destFile.Close() // Insert the file record into the database with creation time currentTime := time.Now().Unix() err = insertFileIntoDatabase(userSession.username, filename, currentTime, currentTime, currentTime) if err != nil { log.Printf("Error inserting file into database: %v", err) - http.Error(w, "Internal Server Error", http.StatusInternalServerError) + http.Error(w, "Internal Server Error when inserting file into database", http.StatusInternalServerError) return } - http.Redirect(w, r, "/home?success=1", http.StatusSeeOther) } + http.Redirect(w, r, "/home?success=1", http.StatusSeeOther) } }