Drupal version: 9.3.3
Issue:
PDF files (.pdf) uploaded to private file system result in a 404 error when trying to view. This occurs even for an admin user with Administrator permissions. Uploaded .txt, .doc, .docx files can be viewed with no issue. This issue is occurring in a production environment – site is hosted on Cloudways
Private directory set in settings.php
- $settings['file_private_path'] = $app_root . '/../private';
Steps to reproduce:
- Login to site as admin (Administrator role)
- Add file field to Article content type
- Set file field "Upload destination" to "Private files"
- Set "Allowed file extensions" is set to txt, pdf, doc, docx. Maximum upload size is set to 1 MB
- Set File directory to
article-test
- My Drupal web root is
public_html/web
- This means private files should be uploaded to
public_html/private/article-test
Then:
- Create an Article (Test article)
- Add Title, Body and upload a valid 150 KB pdf file (
doc_0.pdf
)
- Save and publish Article
- View Test article
- Click on uploaded
doc_0.pdf
(file link shows up ashttps://MYSITE.com/system/files/article-test/doc_0.pdf
)
- Get a 404 Page not found error
- Browser bar shows URL as
https://placerstaffing.com/user/login?destination=/system/files/article-test/doc_0.pdf
- Go to
https://MYSITE.com/admin/content/files
- Click on the file link
https://placerstaffing.com/system/files/article-test/doc_0.pdf
- Get same exact 404 error as above
-
dblog reports:
page not found Location https://MYSITE.com/user/login?destination=%2Fsystem%2Ffiles%2Farticle-test%2Fdoc_0.pdf
-
Remove
doc_0.pdf
file from Test article and upload a text file (with .txt) extension or a MS word file (with .doc or .docx extension) and viewing the file is fine – NO 404 error.- When I view the file .txt or .doc or .docx file, I’m prompted to save or view it.
- I don’t believe this is a permissions issue, otherwise I wouldn’t be able to access these other file types.
public_html/private
dir and lower dirs permissions are 775- Uploaded file (.pdf, .txt, .doc, .docx) permissions are 664
I’m wondering if there’s a PHP setting or Drupal private file setting or server setting that’s missing to allow .pdf files to be viewed ?
There is an .htaccess
file in public_html/private
directory. Thinking that may be related to the issue, I temporarily renamed it .htaccess.saved
and tried to access doc_0.pdf
file with same result.
Any help in resolving this would be greatly appreciated!