mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve mime type detect
This commit is contained in:
parent
bf0799ca0f
commit
3ffc32d089
1 changed files with 7 additions and 1 deletions
|
|
@ -78,7 +78,13 @@ func GetUniqueFilename(filePath string) string {
|
|||
func GetMimeTypeByExt(filePath string) (ret string) {
|
||||
ret = mime.TypeByExtension(filepath.Ext(filePath))
|
||||
if "" == ret {
|
||||
m, err := mimetype.DetectFile(filePath)
|
||||
f, err := filelock.OpenFile(filePath, os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
logging.LogErrorf("open file [%s] failed: %s", filePath, err)
|
||||
return
|
||||
}
|
||||
defer filelock.CloseFile(f)
|
||||
m, err := mimetype.DetectReader(f)
|
||||
if err != nil {
|
||||
logging.LogErrorf("detect mime type of [%s] failed: %s", filePath, err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue