usememos/memos · info
wrong image mediatype
Error message
wrong image mediatype
What it means
The image getter in internal/httpgetter downloaded the URL but the response mediatype did not start with image/, so the bytes are not treated as an image. Unlike the HTML path, this uses plain http.Get (no SSRF-hardened client) and checks only the prefix.
Source
Thrown at internal/httpgetter/image.go:32
}
func GetImage(urlStr string) (*Image, error) {
if _, err := url.Parse(urlStr); err != nil {
return nil, err
}
response, err := http.Get(urlStr)
if err != nil {
return nil, err
}
defer response.Body.Close()
mediatype, err := getMediatype(response)
if err != nil {
return nil, err
}
if !strings.HasPrefix(mediatype, "image/") {
return nil, errors.New("wrong image mediatype")
}
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
image := &Image{
Blob: bodyBytes,
Mediatype: mediatype,
}
return image, nil
}
View on GitHub (pinned to 14d757ce1f)
Solutions
- Use the direct image URL (ends in .png/.jpg or returns image/*), not the page URL
- Verify with `curl -sI <url> | grep -i content-type`
- If you own the server, serve the asset with a correct image/* Content-Type
Example fix
// before
GetImage("https://example.com/photos/cat") // HTML page
// after
GetImage("https://example.com/photos/cat.jpg") Defensive patterns
Strategy: validation
Validate before calling
// Verify the URL returns an image before downloading fully (HEAD)
func isImageURL(u string) bool {
resp, err := http.Head(u)
if err != nil { return false }
return strings.HasPrefix(resp.Header.Get("Content-Type"), "image/")
} Try / catch
// Fall back to a placeholder when the target is not an image
img, err := getter.GetImage(u)
if err != nil && strings.Contains(err.Error(), "wrong image mediatype") {
img = placeholderImage(u)
err = nil
} Prevention
- Validate image URLs with a HEAD request in the client
- Store direct asset URLs, not page URLs, for image fields
- Cap and verify content types at ingest in your own services
When it happens
Trigger: Calling the image fetch with a URL returning text/html (an error page), application/json, application/octet-stream, or video/* content types; hotlink-protected servers returning an HTML login page.
Common situations: Fetching user-supplied avatar/OG-image URLs that are actually HTML pages; CDNs serving the wrong content type; copy-pasting page URLs instead of direct image URLs into image fields.
Related errors
- not a HTML page
- too many redirects
- internal IP addresses are not allowed
- hostname resolved to no addresses
- invalid URL format
AI-assisted analysis of usememos/memos@14d757ce1f (2026-08-15).
Data as JSON: /api/errors/28170aa7f9ce7333.
Report an issue: GitHub.