Browse Source

Initial commit.

Code generally from https://tutorialedge.net/golang/go-file-upload-tutorial/

Code has not been compiled, run, or tested.
master
William Davis 9 months ago
commit
dcb3677bad
  1. 44
      main.go

44
main.go

@ -0,0 +1,44 @@
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func uploader(r *http.Request) {
//i left this out to see what would happen
//r.ParseMultipartForm(10 << 20)
file, header, err := r.FormFile("uploadfile")
if err != nil {
fmt.Println("Error retrieving file")
fmt.Println(err)
return
}
defer file.Close()
fmt.Printf("Uploaded File: %+v\n", handler.Filename)
fmt.Printf("File Size: %+v\n", handler.Size)
fmt.Printf("MIME Header: %+v\n", handler.Header)
tmp, err := ioutil.TempFile("img","upload-*.png")
//MAKE img DIRECTORY
if err != nil {
fmt.Println(err)
}
defer tmp.Close()
bytes, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err)
}
tmp.Write(bytes)
}
func server() {
http.HandleFunc("/upload", uploader)
http.ListenAndServe(":8080", nil)
}
func main() {
server()
}
Loading…
Cancel
Save