You need a web server in Go :
package main
import (
"fmt"
"net/http"
"log"
"io/ioutil"
)
// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
file, handler, err := req.FormFile("file")
if err != nil {
fmt.Println(err)
}
data, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err)
}
err = ioutil.WriteFile(handler.Filename, data, 0777)
if err != nil {
fmt.Println(err)
}
}
func main() {
http.HandleFunc("/upload", HelloServer)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
I don't have any example in ajax right now but a simple form in html
to post file :
<form enctype="multipart/form-data" action="
http://localhost:8080/
upload" method="post">
<input type="file" name="file" />
<input type="submit" value="upload" />
</form>
With Ajax is the same process, you need a form in html and ajax to
post the form.
GGGO