Slide 58
Slide 58 text
29/08/2018 REST, Sockets em Golang
https://go-talks.appspot.com/github.com/jeffotoni/gotalks/server-rest.slide#1 58/70
Copy para servidor único arquivio
func uploadFormFile(w http.ResponseWriter, r *http.Request) {
//sizeUpload := r.ContentLength / 1048576 // 1Mb convert to Mb
file, handler, _ := r.FormFile("fileupload")
r.ParseMultipartForm(10485760)
defer file.Close()
pathUserAcess := PathLocal + "/" + acessekey + "/" + handler.Filename
existPath, _ := os.Stat(PathLocal + "/" + acessekey)
if existPath == nil { os.MkdirAll(PathLocal+"/"+acessekey, 0777) }
f, _ := os.OpenFile(pathUserAcess, os.O_WRONLY|os.O_CREATE, 0777)
defer f.Close()
fmt.Println("Copy: ", pathUserAcess)
sizef, _ := io.Copy(f, file)
fmt.Fprintln(w, "", 500, `{"msg":"ok upload size recebido"}`, sizef, "Bytes")
}