DetectImageMediaType sniffs the media type from the leading bytes and reports whether it is a supported image. Used when an attachment has no declared MIME (local file read, raw paste).
(data []byte)
| 72 | // reports whether it is a supported image. Used when an attachment has |
| 73 | // no declared MIME (local file read, raw paste). |
| 74 | func DetectImageMediaType(data []byte) (string, bool) { |
| 75 | if len(data) == 0 { |
| 76 | return "", false |
| 77 | } |
| 78 | return NormalizeImageMediaType(http.DetectContentType(data)) |
| 79 | } |
| 80 | |
| 81 | // IsValid reports whether the image carries usable bytes (Data or URL) |
| 82 | // and a supported media type. |