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
}
