Drupal 8: How to Get a File URL from a File URI like public://filename Suitable for img src

 

It can take a minute to figure out what method to use to get the file URL from the file URI.

Here's what I did:

file_create_url($file_entity->get('uri')->getString())

Now, mind you, this requires a file entity. Function doc here.

For details on getting that, see this.

About the Author

Hi. My name is Jeremiah John. I'm a sf/f writer and activist.

I just completed a dystopian science fiction novel. I run a website which I created that connects farms with churches, mosques, and synagogues to buy fresh vegetables directly and distribute them on a sliding scale to those in need.

In 2003, I spent six months in prison for civil disobedience while working to close the School of the Americas, converting to Christianity, as one does, while I was in the clink.