diff --git a/meta.go b/meta.go index df2e0b5..d2fb637 100644 --- a/meta.go +++ b/meta.go @@ -15,8 +15,8 @@ import ( "time" "unicode" - "bitbucket.org/taruti/mimemagic" "github.com/dchest/uniuri" + "gopkg.in/h2non/filetype.v1" ) type MetadataJSON struct { @@ -66,7 +66,12 @@ func generateMetadata(fName string, exp time.Time, delKey string) (m Metadata, e header := make([]byte, 512) file.Read(header) - m.Mimetype = mimemagic.Match("", header) + kind, err := filetype.Match(header) + if err != nil { + m.Mimetype = "application/octet-stream" + } else { + m.Mimetype = kind.MIME.Value + } if m.Mimetype == "" { // Check if the file seems anything like text diff --git a/upload.go b/upload.go index 1233d1a..bd2bed6 100644 --- a/upload.go +++ b/upload.go @@ -15,9 +15,9 @@ import ( "strings" "time" - "bitbucket.org/taruti/mimemagic" "github.com/dchest/uniuri" "github.com/zenazn/goji/web" + "gopkg.in/h2non/filetype.v1" ) var fileBlacklist = map[string]bool{ @@ -218,15 +218,12 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) { header = header[:n] // Determine the type of file from header - mimetype := mimemagic.Match("", header) - - // If the mime type is in our map, use that - // otherwise just use "ext" - if val, exists := mimeToExtension[mimetype]; exists { - extension = val - } else { + kind, err := filetype.Match(header) + if err != nil { extension = "ext" } + + extension = kind.Extension } upload.Filename = strings.Join([]string{barename, extension}, ".")