Adding audio/mpeg to mediaTypes allowlist does not seem to work

Trying to download an mp3 file using GetRemote I get the following error:

ERROR Unable to get remote resource http://127.0.0.1:8000/storage/articles/popper-een-afrekening/53d5e6ae-c841-4d06-a0b9-401bfe3cdc74.mp3: error calling resources.GetRemote: failed to resolve media type for remote resource "http://127.0.0.1:8000/storage/articles/popper-een-afrekening/53d5e6ae-c841-4d06-a0b9-401bfe3cdc74.mp3"

And after adding the following lines to my hugo.toml:

[security]
	[security.http]
		mediaTypes = ['^audio/mpeg$']

I get this error:

Error: error building site: process: readAndProcessContent: "/Users/camille/Developer/Home/reactionair.nl/content/articles/_content.gotmpl:68:8": template: /Users/camille/Developer/Home/reactionair.nl/content/articles/_content.gotmpl:68:8: executing "/Users/camille/Developer/Home/reactionair.nl/content/articles/_content.gotmpl" at <$.AddResource>: error calling AddResource: media type "audio/mpeg" not found

Anything I’m doing wrong?

Are you sure that the server at http://127.0.0.1:8000 is returning audio/mpeg as the content type? You can examine the response header in your browser’s dev tools.

Your config works fine for me with v0.127.0.

git clone --single-branch -b hugo-forum-topic-50208 https://github.com/jmooring/hugo-testing hugo-forum-topic-50208
cd hugo-forum-topic-50208
hugo server

Also note that the allow list was added in v0.112.0.

The error suggests that the media type is missing from the config/defaults.

The defaults are listed here:

audio/mpeg isn not in the dfaults, but you can easily add it to your site config.

This seems to have indeed fixed the error. Thanks @jmooring and @bep!

1 Like

I had forgotten about this. Do you happen to remember the conditions under which the allow list additions are required? I can’t remember. It might have been:

  • URLs without extensions
  • Media types not handled by Go’s TypeByExtension
  • Something else

Or maybe the need for allow list additions was eliminated by changes since v0.112.0.

Don’t spend any time on this; only if you remember the details.

The gist of THIS issue is that the mediaType set in AddResource must be a configured media type. resources.GetRemote has some extended logic that I’m not able to spell out from memory on a Saturday night :slight_smile:

2 Likes

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