Suppose I have a link field for internal images. $node->file_image->uri
will for instance return:
internal:/sites/default/files/image/image.jpeg
I need to convert this into an absolute URL for metadata. I can do this manually, of course, but let's see what the usual functions do:
file_create_url() = "https://example.com/internal%3A/sites/default/files/image/image.jpeg"
file_build_uri() = "public://internal:/sites/default/files/image/image.jpeg"
file_create_url(file_build_uri()) = "https://example.com/sites/default/files/internal%3A/sites/default/files/image/image.jpeg"
No cigar, not even close. The new functions?
Url::fromUri()->toString() = "internal:/sites/default/files/image/image.jpeg"
Url::fromUri()->toUriString() = "base:sites/default/files/image/image.jpeg"
So, how to do it without doing it manually, of course? Removing internal:
and prepending $base_url
is very simple but still a hack.