This commit is contained in:
zyj
2025-09-13 10:22:49 +08:00
commit 002419a7ed
28 changed files with 1888 additions and 0 deletions

36
libs/file.go Normal file
View File

@@ -0,0 +1,36 @@
package libs
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"time"
)
type File struct {
}
// 下载图片到临时文件
func (*File) DownloadImage(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
// 创建临时文件
tempDir := os.TempDir()
tempFile := filepath.Join(tempDir, fmt.Sprintf("upload-%d.jpg", time.Now().UnixNano()))
out, err := os.Create(tempFile)
if err != nil {
return "", err
}
defer out.Close()
// 复制文件内容
_, err = io.Copy(out, resp.Body)
return tempFile, err
}