1

I’m having some problems with John Guenin's x_sendfile (http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/).

When coding the download of a PDF file, I’m using the following code:

def send_the_file(filename)
  xsendfile (“#{Rails.root}/doc/” + filename, :type => ‘application/pdf’)
end

but I only get 1 byte downloaded. This usually happens if the filename is not absolute (hence the #{Rails.root} being added. I’ve also checked that the file has the necessary permissions. This is failing both on localhost and my prod site.

Any ideas what I'm doing wrong?

TIA,

Urf

mr_urf
  • 3,303
  • 4
  • 26
  • 29

3 Answers3

3

What version of Rails are you using? If you're on 2.1 or later, the X-Sendfile option is built into Rails' send_file method.

send_file 'filename', :x_sendfile => true

Otherwise, are you sure that mod_xsendfile has been installed and configured correctly?

  • I'm on 2.2.2 and had tried the send_file already. However you could well be right on the mod_sendfile. I asked for it to be set up on my prod server but forgot to install it on dev! Doh! :$ thanks for the reply. – mr_urf Feb 16 '09 at 10:48
2

You may want to make sure that your are actually using a web server that supports xsendfile. If you are dev mode you probably aren't and it may fail.

Goldy
  • 201
  • 1
  • 2
  • 6
0

Try to set in apche httpd.conf file XSendFileAllowAbove on

Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199