Incorrect use of drupal_realpath() in file_resource.inc?

Created on 17 March 2017, almost 8 years ago
Updated 20 September 2023, over 1 year ago

dafdd64

  $file->file = base64_encode(file_get_contents(drupal_realpath($filepath))); 

What is the purpose of drupal_realpath() here? Reversing that commit fixed an issue for me with serving images from S3.

The error was:

Warning: file_get_contents(): Filename cannot be empty in _file_resource_retrieve() (line 268 of sites/all/modules/services/resources/file_resource.inc).

๐Ÿ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States jacob.embree

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Shreya_98

    Shreya_th โ†’ made their first commit to this issueโ€™s fork.

  • @shreya_th opened merge request.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Shreya_98

    Hi @jcnventura,
    we can modify the file_resource_retrieve() function to directly use the file URI without attempting to convert it to an absolute path. I made changes in the code and created MR . Kindly review the changes.

    Thank you.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tyler.frankenstein

    Thank you, @Shreya_h.

    > What is the purpose of drupal_realpath() here?

    From looking at the docs for drupal_realpath():

    Resolves the absolute filepath of a local URI or filepath.

    From my understanding, it would take an input like public://logo.png and return something like https://example.com/sites/default/files/logo.png.

    > Reversing that commit fixed an issue for me with serving images from S3.

    Yeah, I see the docs mention:

    it does not work for remote URIs.

    I don't know if removing the call to drupal_realpath() would be safe for local URIs and I'd want to see/do some tests before committing.

Production build 0.71.5 2024