1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2025-07-17 05:20:28 +00:00

separating out more code

This commit is contained in:
Vincent Batts 2013-05-10 15:03:54 -04:00
parent b38c81e23c
commit ae688c93a9
4 changed files with 34 additions and 23 deletions

27
client/client.go Normal file
View file

@ -0,0 +1,27 @@
package client
import (
"bufio"
"io/ioutil"
"mime"
"net/http"
"os"
"path/filepath"
)
func PutFileFromPath(host, filename string) (path string, err error) {
ext := filepath.Ext(filename)
file, err := os.Open(filename)
if err != nil {
return
}
resp, err := http.Post(host, mime.TypeByExtension(ext), bufio.NewReader(file))
if err != nil {
return
}
bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
return string(bytes), nil
}