发布v2.7.6版本

This commit is contained in:
孟帅
2023-06-19 17:49:34 +08:00
parent aff0ff3af5
commit 773f26b479
23 changed files with 645 additions and 783 deletions

View File

@@ -6,6 +6,8 @@
package storager
import (
"crypto/md5"
"fmt"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
@@ -158,3 +160,20 @@ func UploadFileByte(file *ghttp.UploadFile) ([]byte, error) {
}
return io.ReadAll(open)
}
// CalcFileMd5 计算文件md5值
func CalcFileMd5(file *ghttp.UploadFile) (string, error) {
f, err := file.Open()
if err != nil {
err = gerror.Wrapf(err, `os.Open failed for name "%s"`, file.Filename)
return "", err
}
defer f.Close()
h := md5.New()
_, err = io.Copy(h, f)
if err != nil {
err = gerror.Wrap(err, `io.Copy failed`)
return "", err
}
return fmt.Sprintf("%x", h.Sum(nil)), nil
}