Skip to content

Instantly share code, notes, and snippets.

@skelterjohn
Created February 25, 2012 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skelterjohn/1909621 to your computer and use it in GitHub Desktop.
Save skelterjohn/1909621 to your computer and use it in GitHub Desktop.
func write(localFile, remoteFile string) (err error) {
buf := bytes.NewBuffer([]byte{})
mw := multipart.NewWriter(buf)
if err = mw.WriteField("field", value); err != nil {
return
}
pw, err := mw.CreateFormField(localFile)
if err != nil {
return
}
lf, err := os.Open(localFile)
if err != nil {
return
}
_, err = io.Copy(pw, lf)
if err != nil {
return
}
err = mw.Close()
if err != nil {
return
}
// path package messes up the protocol
fsurl := url + "/" + remoteFile
fmt.Println("about to POST to", fsurl)
response, err := http.Post(fsurl, "mime", buf)
if err != nil {
return
}
_ = response
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment