// GetFileMd5 count file's md5
// return md5 string
func GetFileMd5(file multipart.File) (md5Str string) {
h := md5.New()
if _, err := file.Seek(0, 0); err != nil {
log.Error("Get file md5 error: %v", err)
}
if _, err := io.Copy(h, file); err != nil {
log.Error("Get file md5 error: %v", err)
}
md5Str = hex.EncodeToString(h.Sum(nil))
log.Debug("File md5 is: %s", md5Str)
return md5Str
}
Your code looks ok, but check, how you receive and store files. If you store them in memory, then you shouldn't call Seek
method.
If you want to calculate hash of uploaded file and in the same time save it locally or upload to the cloud, then you can use MultiWriter.