I have an audio file that is stored as Media of type Audio.

Now I want to get the link to that file that is usually displayed to site users via jsonapi.

For example, when the media entity is rendered, this is the link:

<audio controls="" controlslist="nodownload"> <source src="/sites/default/files/coolstuff/audio/apples-bananas-pears.mp3" type="audio/mpeg"> </audio>

This /sites/default/files/coolstuff/audio/apples-bananas-pears.mp3 path is what I want to get from jsonapi.

However, when I look at the output of /jsonapi/media/audio, all the URLs look like this:


None of them have the public-facing URI.

The documentation gives this example for a "article media entity reference field_image url, uri by including references":


I have media entity references, so I tried the same on my site:


However, I do not get the regular media URI, just the jsonapi one.

How can I get the media public file URI (/sites/default/files/coolstuff/audio/apples-bananas-pears.mp3)?

1 Answer 1


Here's the correct path:


This results in a value for uri such as:

"value": "public:/sites/default/files/coolstuff/audio/apples-bananas-pears.mp3",
  • are you aware of anyway to flatten this out a bit? This means my front-end needs to loop included for the field_media.uuid, then loop its relationships for the its file--file.uuid, then back up across included to find file-file.attributes.uri.url
    – E.A.T
    Aug 31, 2021 at 4:48
  • @E.A.T No, I don't know a way to simplify this. There is the JSON:API Resources module to define your own custom resource if you want to write all the logic yourself on the backend. Sep 1, 2021 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.