1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2024-11-27 18:45:40 +00:00
imgsrv/client/client.go

28 lines
464 B
Go
Raw Normal View History

2013-05-10 19:03:54 +00:00
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
}