Question

I have a Rails 4.1.0 app running with nginx, hosted on Engineyard. I'm having some puzzling issues with the send_file method (also tried send_data) with pdf files.

The setup:

In my controller:

send_file path, type: asset_content_type, disposition: 'inline', filename: filename

I have confirmed with logger that all the variables in the above line are correct. I uncommented this line in the config for the environment in question:

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

Here's the paperclip setup on the model:

class Asset < ActiveRecord::Base

  belongs_to :attachable, polymorphic: true

  has_attached_file :asset,
    styles: lambda { |i| i.instance.attachable_styles },
    path:   ':rails_root/private/system/:attachment/:id_partition/:style/:filename',
    url:    '/files/:id/disposition/:style/:hash.:extension',
    preserve_files: true

  validates_attachment_content_type :asset, :content_type => /.*/

The symptoms:

  • No problems at all locally running POW or webrick.
  • With the app running remotely, downloading any kind of image file of any size works normally.
  • Downloading pdfs ~ 140KB or less works normally.
  • Downloading pdfs larger than that, I get a fraction of the file. Say I have a 1MB pdf. I download it, and end up with a corrupted file that is around 140KB.
  • I have confirmed that file on disk is fine. I can scp the same large pdf to my local machine, and the pdf is fine.
  • The paperclip record in the db is normal.

Maybe it's an nginx config issue I'm overlooking?

EDIT: The pdf thing is a red herring. It appears all large files are only partially sent.

Was it helpful?

Solution

EY support gave me a hand. Here are the steps they followed to solve the issue:

  • Noted the directories that nginx was referencing did not seem to match up with what was in /var/tmp/nginx/proxy.
  • Removed all the temporary folders in /var/log/nginx/proxy, and restarted nginx.

Now it works.

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