send_file sends 0 bytes in production mode

send_file sends 0 bytes in production mode

In one of my recent Rails3 projects I implemented a download possibility with the "send_file" method. It worked fine in development mode, but after deploying the app it did not work anymore. The result always was an 0 byte file. The downloaded file always was blank.

My solution for this problem:
I just uncomment the following line in config/environments/production.rb

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

I think it depends which server type (linux, debian, windows, etc.) you use in your background, but this was the solution for me. By the way I am using a linux server in this case.

It is just really simple, but maybe you save some time through this short blogpost :-).

Matthias Frick
Ruby on Rails
3 Kommentare

Über den Autor

Matthias Frick
Matthias Frick, MSc.

Er ist ein langjähriger Ruby-on-Rails Entwickler und leitet das Unternehmen Frick-Web.

3 Kommentare zu "send_file sends 0 bytes in production mode"

  1. Harold Olword
    Harold Olword 12.07.2011
    simple and easy, that's the way I like it. saved me a good time, thanks boy!
  2. Mike
    Mike 04.08.2011
    Very useful!
  3. Bali Muhammar
    Bali Muhammar 08.08.2011
    Exactly what I was looking for! Thanks!

Kommentar verfassen