1234567891011121314151617181920212223242526272829 |
- package services
- import (
- "io"
- "mime/multipart"
- "os"
- )
- // SaveUploadedFile 保存上传的本地文件
- func SaveUploadedFile(file *multipart.FileHeader, fpath string) (err error) {
- src, err := file.Open()
- if err != nil {
- return err
- }
- defer func() {
- _ = src.Close()
- }()
- out, err := os.Create(fpath)
- if err != nil {
- return err
- }
- defer func() {
- _ = out.Close()
- }()
- _, err = io.Copy(out, src)
- return
- }
|