photoprism/pkg/fs/mime.go
Michael Mayer b020b4e415 Sync: Ignore unsupported file types #225
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-04-07 10:42:42 +02:00

33 lines
483 B
Go

package fs
import (
"net/http"
"os"
)
const (
MimeTypeJpeg = "image/jpeg"
)
// MimeType returns the mime type of a file, empty string if unknown.
func MimeType(filename string) string {
handle, err := os.Open(filename)
if err != nil {
return ""
}
defer handle.Close()
// Only the first 512 bytes are used to sniff the content type.
buffer := make([]byte, 512)
_, err = handle.Read(buffer)
if err != nil {
return ""
}
return http.DetectContentType(buffer)
}