resources.GetRemote: failed to resolve media type (image/jpeg)

This works fine for me:

{{ $url1 := "https://upload.wikimedia.org/wikipedia/commons/a/a5/Red_Kitten_01.jpg" }}
{{ with try (resources.GetRemote $url1) }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ end }}
{{ end }}

This does not:

{{ $url2 := "https://octodex.github.com/images/stormtroopocat.jpg" }}
{{ with try (resources.GetRemote $url2) }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ end }}
{{ end }}

Here an error is thrown:

ERROR template: _shortcodes/bild.html:10:22: executing "_shortcodes/bild.html" at <resources.GetRemote>: error calling GetRemote: failed to resolve media type for remote resource "https://octodex.github.com/images/stormtroopocat.jpg"

The media type for both files is exactly the same:

curl -s -I https://upload.wikimedia.org/wikipedia/commons/a/a5/Red_Kitten_01.jpg https://octodex.github.com/images/stormtroopocat.jpg | grep content-type:content-type: application/javascript; charset=utf-8
content-type: image/jpeg
content-type: image/jpeg

What’s wrong with the second image? How can I avoid the error?

It might be connected to github.com, not the image itself. I am experiencing plenty of weird issues when retrieving stuff from GitHub via public URLs (not just via Hugo, but also in other tools/scripts). You might want to check if the image is available via REST API and then use that URL instead of what loading the image in a web browser would result in.

This might be an URL that you can actually load.

This:

https://octodex.github.com/images/stormtroopocat.jpg

Is a PNG file with the wrong extension.

1 Like

Thanks for pointing that out!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.