Skip to content

Commit

Permalink
fix: support detect mimeType by the file ext
Browse files Browse the repository at this point in the history
  • Loading branch information
saltbo committed May 18, 2020
1 parent 9b1e93e commit 26fee6b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"encoding/hex"
"io"
"io/ioutil"
"mime"
"net/http"
"os"
"path"
)

// FileMD5 returns the file md5 hash hex
Expand All @@ -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 ""
Expand Down

0 comments on commit 26fee6b

Please sign in to comment.