Created
January 11, 2023 14:16
-
-
Save nikolaydubina/6d8ec2bf3dd47b5d7c3a0ecc607e815e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// locally can upload tens of GBs | |
package main | |
import ( | |
"fmt" | |
"io" | |
"net/http" | |
"os" | |
"path" | |
) | |
const uploadPageHTML = ` | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<form action="/upload" enctype="multipart/form-data" method="post"> | |
<input type="file" name="file"> | |
<input type="submit" name="submit"> | |
</form> | |
</body> | |
</html> | |
` | |
func upload(w http.ResponseWriter, r *http.Request) { | |
r.ParseMultipartForm(1024 * 1024 * 1024 * 1024) | |
file, handler, _ := r.FormFile("file") | |
defer file.Close() | |
fmt.Fprintf(w, "%v", handler.Header) | |
dir, _ := os.Getwd() | |
f, _ := os.OpenFile(path.Join(dir, handler.Filename), os.O_WRONLY|os.O_CREATE, 0666) | |
defer f.Close() | |
io.Copy(f, file) | |
} | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, uploadPageHTML) }) | |
http.HandleFunc("/upload", upload) | |
http.ListenAndServe(":8090", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment