Error generating .zip files in prod (Rails 3)

I use Linode as my hosting solution. I have a rails 3 application that dynamically accepts mp3 (and other media) and creates a ZIP file for download. It works fine in development, but as soon as I put it on my prod server, the zip file is still loading, but when I unzip it, it creates a file called foo-bar.zip.cpgz

heres my controller snippet -

   def get_zip
    t = Tempfile.new("#{@foobar.slug}-#{request.remote_ip}.zip")
    Zip::ZipOutputStream.open(t.path) do |zos|
      @foobardownloads.each do |foobardownload|
        extension = File.extname(foobardownload.foobardownload_file_name).gsub(/^\.+/, '')
        zos.put_next_entry("#{foobardownload.title}.#{extension}")
        zos.print open(foobardownload.foobardownload.url).read
      end
    end
    send_file t.path, :x_sendfile => true, :type => 'application/zip', :filename => "#{@foobar.slug}.zip"
    t.close  
  end
+3
source share
1 answer

ok - did a little digging - this is actually a problem with rails 3, nginx and send_file. the solution is here:

http://www.novafist.com/2010/09/send_file-sends-0-bytes-to-client-in-rails/

" " , production.rb

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

,

#config.action_dispatch.x_sendfile_header = "X-Sendfile"

.

+6

Source: https://habr.com/ru/post/1786925/