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:
parent
b38c81e23c
commit
ae688c93a9
4 changed files with 34 additions and 23 deletions
27
client/client.go
Normal file
27
client/client.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue