0

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:

http://mysite.com/jsonapi/media/audio/d741b59c-9617-4a24-a2e8-99005a76507b?resourceVersion=id%3A31"

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":

http://example.com/jsonapi/node/article/{{article_uuid}}?include=field_image&fields[file--file]=uri,url

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

http://mysite.com/jsonapi/node/MY_CONTENT_TYPE?include=field_ref_media_audio&fields[file--file]=uri,url

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)?

0

Here's the correct path:

http://mysite.com/jsonapi/node/MY_CONTENT_TYPE?include=field_ref_media_audio.field_media_audio_file&fields[file--file]=uri,url

This results in a value for uri such as:

"value": "public:/sites/default/files/coolstuff/audio/apples-bananas-pears.mp3",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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