feat:gemini file

This commit is contained in:
suziheng
2025-09-15 17:16:50 +08:00
parent a529eab39e
commit 974331a028
4 changed files with 45 additions and 5 deletions

23
common/file/file.go Normal file
View File

@@ -0,0 +1,23 @@
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
}