0

So inside my hook function I have URI of some file and I need to find it's S3 path (using s3fs module). How can I do that, to avoid manual string manipulation? Is there some helper function?

I found convertUriToKeyedPath() of S3fsStream class but it's protected and also it says "Converts a Drupal URI path into what is expected to be stored in S3" and that "expect is potentially dangerous.

1 Answer 1

0

Use file_url_generator service:

$uri = 's3://bucket/file.ext';
$url = \Drupal::service('file_url_generator')->generateAbsoluteString($uri);

An old way (deprecated as of 9.3):

$http_url = file_create_url($uri);
1
  • No, it's opposite. I have drupal URI of file and I need to find S3 path.
    – MilanG
    Oct 6, 2022 at 14:29

Your Answer

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

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