Problem/Motivation
When used in conjunction with the S3 File System module, thumbnail generation throws an exception:
TypeError: md5_file() expects parameter 1 to be a valid path, bool given in md5_file() (line 195 of /var/www/web/modules/contrib/brightcove/src/Entity/BrightcoveVideo.php)
Steps to reproduce
- Install both the brightcove and s3fs modules.
- Configure Brightcove.
- Configure S3fs and enable the s3fs.use_s3_for_public option so that S3 takes over the public:// file handler.
- Run the Brightcove cron job and check the error log.
Proposed resolution
The problem is caused by lines 194 and 195 of BrightcoveVideo:
$file_path = $file_system->realpath($file->getFileUri());
$file_md5 = md5_file($file_path);
With the s3fs.use_s3_for_public option enabled, the S3 module replaces the public:// file handler with its own. Because S3 is a remote stream wrapper, realpath() will return false, thus triggering the exception when that is passed to md5_file(). This could be solved by changing line 195 to set $file_md5 to false if the $file_path is false, like so:
$file_md5 = $file_path ? md5_file($file_path) : FALSE;
This is essentially the same result as if md5_file() had failed to calculate the file's hash, which is arguably what is happening here given that there isn't a standard method for getting a file's MD5 hash from a remote stream.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | brightcove-md5-exception-3278712-6.patch | 971 bytes | yce |
| #4 | brightcove-md5-exception-3278712-4.patch | 657 bytes | muriqui |
Issue fork brightcove-3278712
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
muriqui commentedPush proposed fix as MR !20.
Comment #4
muriqui commentedPatch file for those who may need it.
Comment #5
eveyrat commentedHi,
I'm having the exact same issue and confirm that the patch fixed the issue.
Thanks a lot @muriqui
Comment #6
yce commentedHi,
I would still try to calculate the hash for the file in case of remote paths.
Seems like passing the file URI as-is to the md5_file() function works.
I've also added a condition to make sure that the file exist before the hash calculation is attempted.
Please let me know if it works for you as well.
Comment #7
awolfey commentedI encountered this error in a different situation, and the patch in #6 also works for me. Thanks.
Comment #8
yce commentedIs it still an issue with Drupal 10.2 (or above) and Brightcove 3.2.0?
As part of another issue I've just tested s3fs and I did not notice any errors now.
Comment #9
yce commentedI'm going to assume it is fixed.