Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"fmt"
"net/http"
)
func uploadHandler(w http.ResponseWriter, r *http.Request) {
err := r.ParseMultipartForm(10 << 20)
if err != nil {
fmt.Fprintln(w, "Invalid file upload")
return
}
file, header, err := r.FormFile("file")
if err != nil {
fmt.Fprintln(w, "File not found")
return
}
defer file.Close()
fmt.Fprintln(w, "Uploaded:", header.Filename)
}
func main() {
http.HandleFunc("/upload", uploadHandler)
fmt.Println("Upload API running on :8080")
http.ListenAndServe(":8080", nil)
}Coding works best on desktop or with an external keyboard.