views:

540

answers:

3

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

+1  A: 

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?

Jeremy Weiskotten
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.
Urf
+1  A: 

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
A: 

hey try to set in apche httpd.conf file XSendFileAllowAbove on

AMIT