Question

I recently upgraded a Rails 2.3 application to Rails 4. One feature of the app is to upload PDF files which will then be stored in the database. It is also possible to download those PDFs. However, some (about 20%) downloaded PDF files cannot be displayed by the PDF viewer ("PDF document is damaged"). Strange to say I can download the same PDFs from the same database using Rails 2.3 and everything is okay. This leads me to the assumption that the PDFs in the database are not corrupted, but something goes wrong when Rails 4 delivers them.

This is the corresponding code that sends the PDF files:

def show_pdf_document
  send_data @files.pdf.binary_data, :filename => @files.pdf.filename, :type =>@files.pdf.filetype
end

Might it be an encoding issue?

Update: The problem doesn't seem to be directly related to Rails 4. I have a Unicorn/nginx setup. When I connect directly to the Unicorn worker it works without any problems. It's nginx that seems to corrupt the PDFs.

Was it helpful?

Solution

The problem had something to do with Unicorn and Nginx. However, I didn't find the exact source of the problem. In this case, the most practical solution was to replace Unicorn/Nginx with Passenger/Nginx. Works like a charm now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top