Currently, PDF Preview module uses file_default_scheme() as the file system for all preview images.

I'd suggest that PDF Preview module should choose the file system for a preview image based on that of its parent PDF file. For example, if a PDF is uploaded to the private file system, its preview image should be private; if a PDF is uploaded to the public file system, its preview image should be public; etc.

Patch is attached.

Comments

mfb created an issue. See original summary.

mfb’s picture

mfb’s picture

Anyone have time to take a look at this patch?

helmo’s picture

Status: Needs review » Reviewed & tested by the community

I have this patch on prd for a while now ... seems to work great.

edvanleeuwen’s picture

Tested and verified.

rcodina’s picture

Patch works for me too. Thanks!

I had problems with PDF previews (403 and 404 errors) when using "Private local files served by Drupal" for file fields configured to store files on private destination. I was using 7.x-2.1. However, to fix the problem, I downloaded latest version using git and then applied file-scheme_1.patch. Then all started working like a charm.

mfb’s picture

Not sure anyone is maintaining this module these days? We might need a new maintainer to get this committed?

rcodina’s picture

@mfb Someone should contact the module maintainer and ask for co-maintainer permissions. Last commit is from 18 Feb 2016. There are other important issues solved like #2315257: Generated image links to the image rather than the PDF file.

edvanleeuwen’s picture

I think this is not enough. The preview image file should be registered as managed file as well.

Or you could set the path to public:// hardcoded, but then you should be careful with files which are supposed to be restricted.

mfb’s picture

I'd agree the preview images should be managed, but that should be a separate feature request.

edvanleeuwen’s picture

Isn't it related? The problem is that for the private filesystem, there has to be an entry in the file_managed table to give you access to the thumbnail.

mfb’s picture

My default file system is set to private, but I want to generate PDF previews for certain file fields that are public. So this patch resolves the issue that PDF Preview module was forcing me to use my default file system for previews.

mstrelan’s picture

Version: 7.x-2.x-dev » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new736 bytes

This will need to be committed to 8.x first. Can someone test this patch against the latest dev snapshot?

mstrelan’s picture

I'm reluctant to add this without config options. I can see a use case where public thumbnails are generated for private documents, and the user it not required to authenticate until accessing the actual PDF. So I think we should default to matching the source file with the possibility to override with public.

mstrelan’s picture

Status: Needs review » Needs work
StatusFileSize
new5.32 KB

Config options added to attached patch. Needs work because displaying the image from the private file system throws access denied.

mstrelan’s picture

If we want to use the private file system then we need to do an access check against the original file, and/or provide a permission to skip access checks. We can use image_file_download() as an example but due to our filename handling we can't reliably find the source file. One option would be to create a mapping of file id to pdfpreview path, another would be to standardize the preview path similar to image.module

mstrelan’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Related issues: +#2346003: Preview image as managed file

This will be easier once #2346003: Preview image as managed file is in.