mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-17 09:16:36 +08:00
24 lines
434 B
Go
24 lines
434 B
Go
package file
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/base64"
|
|
"net/http"
|
|
)
|
|
|
|
func GetFileFromUrl(url string) (mimeType string, data string, err error) {
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
buffer := bytes.NewBuffer(nil)
|
|
_, err = buffer.ReadFrom(resp.Body)
|
|
if err != nil {
|
|
return
|
|
}
|
|
mimeType = resp.Header.Get("Content-Type")
|
|
data = base64.StdEncoding.EncodeToString(buffer.Bytes())
|
|
return
|
|
}
|