From b7f722a8459b31e300169fc1f601fc05b6c1111a Mon Sep 17 00:00:00 2001 From: Calamitas Date: Mon, 18 Jul 2022 23:41:28 -0500 Subject: [PATCH] --- README.md | 2 +- fileboard.go | 45 --------------------------------------------- 2 files changed, 1 insertion(+), 46 deletions(-) delete mode 100644 fileboard.go diff --git a/README.md b/README.md index a3ee87a..aa78b2f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Shitty image upload package +# Shitty image upload package ```sh go run image_upload.go diff --git a/fileboard.go b/fileboard.go deleted file mode 100644 index 6381a77..0000000 --- a/fileboard.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "log" - "net/http" -) - -// GLOBAL -func filehandler(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "files") -} -func uploadhandler(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "index.html") - fmt.Println("Upload your image here") - if err := r.ParseMultipartForm(32 << 20); err != nil { - http.Error(w, "File is too big", http.StatusBadRequest) - } - file, handler, err := r.FormFile("myFile") - if err != nil { - fmt.Println("Cannot retrieve file") - fmt.Println(err) - return - } - defer file.Close() - fmt.Printf("Uploaded File: %+v\n", handler.Filename) - - tempFile, err := ioutil.TempFile("files", "upload-*.png") - if err != nil { - fmt.Println(err) - } - defer tempFile.Close() - fileBytes, err := ioutil.ReadAll(file) - if err != nil { - fmt.Println(err) - } - tempFile.Write(fileBytes) - fmt.Fprintf(w, "Successfully uploaded File\n") -} -func main() { - http.HandleFunc("/upload", uploadhandler) - http.HandleFunc("/files", filehandler) - log.Fatal(http.ListenAndServe(":8081", nil)) -}