From 26fee6b39e7d7d97ed29438b2d1bf033f6ae3312 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 18 May 2020 11:39:03 +0800 Subject: [PATCH] fix: support detect mimeType by the file ext --- utils/utils.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index 76b47bf..3c61739 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -5,8 +5,10 @@ import ( "encoding/hex" "io" "io/ioutil" + "mime" "net/http" "os" + "path" ) // FileMD5 returns the file md5 hash hex @@ -27,6 +29,11 @@ func FileMD5(filepath string) string { // FileContentType returns the file content-type func FileContentType(filepath string) string { + mimeType := mime.TypeByExtension(path.Ext(filepath)) + if mimeType != "" { + return mimeType + } + fileData, err := ioutil.ReadFile(filepath) if err != nil { return ""