The module works fine if you are using local file storage through a default schema such as public://, but fails when attempting to use a remote object store and interface through a Stream Wrapper such as FlySystem / Flysystem S3.
The failure point is in the call to MediaPdfThumbnailImageManager::getFileInfos(), when a call is made to FileSystem::realpath(). This will return FALSE when using a StreamWrapper -- the files are not located on the local file system so this is not a valid call.
However code current assumes that a string will be returned that can be used to create a destination for the thumbnail image, which results in a downstream notice and subsequent failure:
Notice: Trying to access array offset on value of type bool in Drupal\media_pdf_thumbnail\Manager\MediaPdfThumbnailImageManager->setImageToMediaThumbnail() (line 176 of /var/www/html/web/modules/contrib/media_pdf_thumbnail/src/Manager/MediaPdfThumbnailImageManager.php)
Please support Remote Object Stores such as Amazon S3, with a StreamWrapper interface (FlySystem / FlySystem S3 works great for that).
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | media_pdf_thumbnail-stream-wrappers-compability-3193078-2.patch | 4.46 KB | ayrmax |
| #2 | media_pdf_thumbnail-stream-wrappers-compatibility-3193078-1.patch | 649 bytes | martins.bertins |
Comments
Comment #2
martins.bertins commentedSticking with uris seems to work. Even FileSystemInterface::realpath() function documentation discourages it's usage.
Patch attached.
Comment #3
steven buteneers commented@martins.bertins Did you get this working with flysystem? With your patch I'm getting one step further but imagick is failing to generate the PDF.
Comment #4
ayrmax commentedI am using media_pdf_thumbnail with the remote_stream_wrapper module. This streamwrapper is read only. The media_pdf_thumbnail tries to write to the same destination as its source by default. That does not work in my case. The imagestyle module faces the same issue and solves it by checking if the streamwrapper does support
WRITEoperations and falls back to the default streamwrapper of the site in case it cannot write to its source.Additionally the latest version of the spartie/pdf-to-image implementation does merge all pages of a remote pdf file into one image.
https://github.com/spatie/pdf-to-image/issues/180
I was able to fix this issue by changing the layer method (
$pdf->setLayerMethod(null)->saveImage($target);).I provided a patch to fix those issues.
Comment #5
sgostanyan commented