29 lines
498 B
Go
29 lines
498 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
var allowedTypes = map[string]bool{
|
|
"image/jpeg": true,
|
|
"image/jpg": true,
|
|
"image/png": true,
|
|
"image/gif": true,
|
|
"image/webp": true,
|
|
"image/bmp": true,
|
|
}
|
|
|
|
func IsImageMime(data string) bool {
|
|
return allowedTypes[data]
|
|
}
|
|
|
|
func GetImageMimeType(data []byte) (string, error) {
|
|
content_type := http.DetectContentType(data)
|
|
|
|
if !IsImageMime(content_type) {
|
|
return "", errors.New("Unexpected image format.")
|
|
}
|
|
|
|
return content_type, nil
|
|
}
|