Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.