开发者

Issue generating .zip files in prod (Rails 3)

I'm using Linode as my hosting solution. I have a rails 3 app that dynamically takes mp3s (and other media) and creates a .zip file for download. It works fine in development but once i put it on my prod server the zip file still downloads but when i uncompress it, it creates a file called foo-bar.zip.cpgz

heres a code snippet f开发者_如何学Crom my controller -

   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


ok - did a bit of digging - this was actually an issue w/ rails 3 , nginx, & send_file. the solution is here:

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

the "quick and dirty" hack would be to open your production.rb file and uncomment this line

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

make sure the

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

is still commented out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜