private files are not loaded

Created on 25 June 2020, over 4 years ago
Updated 2 June 2024, 7 months ago

I have a private file field and my attached pdf isn't loaded with pdf.js both in the form and in the display view

🐛 Bug report
Status

Active

Version

1.0

Component

Miscellaneous

Created by

🇮🇹Italy kimlop

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇩Indonesia tinohuda

    I have drupal 9 webform and files element (private file system), if i access the file its always downloaded, when i use pdf.js its not loaded.

    I've add header Content-Disposition: Inline in the nginx conf

    # Handle PDFs to display inline
    location ~* \.pdf$ {
        add_header Content-Type application/pdf;
        add_header Content-Disposition "inline; filename=\"$uri\"";
        try_files $uri /index.php?$query_string;
    }
    
    # Private files handled by Drupal
    location /system/files/webform/ {
        internal;
        try_files $uri /index.php?$query_string;
    }
    
    # Custom handling for PDFs in private files
    location ~* ^/system/files/webform/.+\.pdf$ {
        types { application/pdf pdf; }
        add_header Content-Type application/pdf;
        add_header Content-Disposition "inline; filename=\"$uri\"";
        try_files $uri =404;
    }

    Unfortunately the pdf still cannot open in the browser, its always downloaded.

    I check in the Browser Header content Content-Disposition valeu is attachment.

    But when i try to direct access via php it's work.

    <?php
    header('Content-Type: application/pdf');
    header('Content-Disposition: inline; filename="example.pdf"');
    readfile('/system/files/webform/example.pdf');

    Anyone can assist me how to make pdf in drupal private files can display in the browser, so I can display via pdf.js.

    Thank you for help.

Production build 0.71.5 2024