Created
February 25, 2012 17:24
-
-
Save skelterjohn/1909621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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