diff --git a/index.html b/index.html index 5cc1d26..d1b880a 100644 --- a/index.html +++ b/index.html @@ -5,11 +5,11 @@
Test
- - - - diff --git a/main.go b/main.go index 338d7f8..b2e15fb 100644 --- a/main.go +++ b/main.go @@ -24,13 +24,29 @@ func getRoot(w http.ResponseWriter, r *http.Request) { func uploadFile(w http.ResponseWriter, r *http.Request) { fmt.Printf("Received upload!\n") - fmt.Println(w, "You have uploaded something") + fmt.Fprintln(w, "You have uploaded something") + + file, header, err := r.FormFile("file") + + if err != nil { + log.Printf("Error happened receiving file: %v\n", err) + } + fmt.Fprintf(w, "%v", header.Header) + f, err := os.OpenFile("./temp/"+header.Filename, os.O_WRONLY|os.O_CREATE, 0660) + if err != nil { + log.Printf("Error happened opening file: %v\n", err) + } + io.Copy(f, file) + + defer file.Close() } func main() { http.HandleFunc("/", getRoot) http.HandleFunc("/api/upload", uploadFile) + fmt.Println("Listening on port 8080...") + err := http.ListenAndServe(":8080", nil) if err != nil { log.Fatal(err) diff --git a/temp/.gitignore b/temp/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/temp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore