Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Serving PDF files from MySQL

$
0
0
We have a large number of PDF files that are stored as LONGBLOBs in a MySQL database.
We've written a Drupal-based PHP module that pulls the LONGBLOB data and formats it as a PDF download from the web page.

The PHP module adds the Content-Type: application/pdf and Content-Length: and Accept-Ranges: bytes headers (via php "header()" function) and then echoes the LONGBLOB data. (The headers and LONGBLOB are encapsulated in ob_start() / ob_end_flush() )

On the Nginx side, the relevant part of the config file looks like this:

# location ~ ^/support/userdoc/.*\.pdf {
location /support/userdoc/ {
default_type application/pdf;
add_header Content-Type 'application/pdf';
add_header Last-Modified $date_gmt;
if_modified_since off;
etag off;
}


location ~* \.(?:js|css|html|xml|png|jpg|mp4|pac|pdf|obj|mtl|doc|docx|jpeg|svg|gif|ico|gz|zip|crt|xlsm|ttf|vtt|eot|potx|woff|woff2)$ {
expires max;
add_header Cache-Control 'public, max-age=31536000, immutable';
# Below header allows server to display ttf/eot/woff/woff2 fonts
add_header Access-Control-Allow-Origin *;
log_not_found off;
access_log off;
tcp_nodelay on;
keepalive_timeout 65;
gzip_static on;
try_files $uri $uri/ @rewrite;
}


The "most specific" match seems to be the first one. Because no actual files are being sent, I've turned off etag.

The problem is that the LONGBLOB is sometimes sent as text/html (incorrect) and sometimes as application/pdf (correct).
And the Content-Length value is never sent.

(Obviously, I'd like to have the Content-type set to application/pdf for all of the LONGBLOB-based downloads)

The page in question is at https://www.sonosite.com/support/user-documents



Any suggestions would be most appreciated! Thank you.

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>