Score:2

I cannot access PDF files uploaded in the private directory

gb flag

PDF files uploaded to the private directory cannot be viewed and returns a 404 error. This also happens to the user with the Administrator role. Other file types can be viewed with no issue. This issue happens in a production environment, hosted on Cloudways, where the private directory is set from the following line in the settings.php file.

$settings['file_private_path'] = $app_root . '/../private';

Steps to reproduce

  • Login to site as administrator user (the one with the Administrator role)

  • Add a file field to the Article content type

  • Set its Upload destination to Private files

  • Set Allowed file extensions to txt, pdf, doc, docx and Maximum upload size to 1 MB

  • Set the file directory to article-test (When the server root directory is public_html/web, private files should be uploaded to public_html/private/article-test.)

  • Create an Article node and upload a valid PDF file whose size is less than 1 MB (doc_0.pdf)

  • Save and publish the node

  • View the new node

  • Click on the file link for the uploaded file, which links to https://<domain>/system/files/article-test/doc_0.pdf)

  • The site returns a 404 error

  • The browser bar shows https://<domain>/user/login?destination=/system/files/article-test/doc_0.pdf as URL

  • Go to https://<domain>/admin/content/files

  • Click on the file link (https://<domain>/system/files/article-test/doc_0.pdf)

  • The site still returns a 404 error

  • The Drupal log shows page not found Location https://<domain>/user/login?destination=%2Fsystem%2Ffiles%2Farticle-test%2Fdoc_0.pdf

  • Remove the uploaded file from the node

  • Upload a text file or a Microsoft Word file

  • Viewing the file doesn't return any 404 error

  • viewing the file, a prompts ask for saving or viewing the file

I don't believe this is a permissions issue; otherwise, I wouldn't be able to access these other file types.

The file permissions for the public_html/private directory and its directories are set to 775. The file permissions for the uploaded files are set to 664.

Is there a setting (PHP, Drupal, or server) I should change to allow the PDF files to be viewed?

There is an .htaccess file in public_html/private directory. Thinking it may be related to the issue, I temporarily renamed it to .htaccess.saved. I then tried to access the uploaded PDF file, still obtaining a 404 error.

One more fact: If the same exact PDF file is uploaded to the site's public directory, the file can be viewed without errors.

id flag
Drupal serves private files by reading them from the filesystem so I doubt `.htaccess` is anything to do with this. Is the configured directory for private files on a different filesystem than the public directory?
id flag
Some related: https://www.drupal.org/node/2911882
rmompoin avatar
gb flag
The private directory is in the same file system as the public directory. This issue https://www.drupal.org/project/webform/issues/3098553 on drupal.org seems to be the solution. I've asked the author for more details on the solution
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.