From: Tom Hughes Date: Sat, 24 Sep 2011 17:21:56 +0000 (+0100) Subject: Make hack for file streaming work with rails 3.1.0 X-Git-Tag: live~6094 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/c0fe77fd020a102ee0ac3cde974b437f31efc817?hp=8d520578a1e7b62bc2796f7c527c621e1b3c87cb Make hack for file streaming work with rails 3.1.0 --- diff --git a/config/initializers/streaming.rb b/config/initializers/streaming.rb index 116ca51dd..0fc092951 100644 --- a/config/initializers/streaming.rb +++ b/config/initializers/streaming.rb @@ -1,28 +1,16 @@ -# Hack ActionController::Streaming to allow streaming from a file handle +# Hack ActionController::DataStreaming to allow streaming from a file handle module ActionController - module Streaming + module DataStreaming alias_method :old_send_file, :send_file def send_file(file, options = {}) if file.is_a? File or file.is_a? Tempfile - options[:length] ||= file.stat.size options[:filename] ||= File.basename(file.path) unless options[:url_based_filename] send_file_headers! options - @performed_render = false - - if options[:stream] - render :status => options[:status], :text => Proc.new { |response, output| - logger.info "Streaming file #{file.path}" unless logger.nil? - len = options[:buffer_size] || 4096 - while buf = file.read(len) - output.write(buf) - end - } - else - logger.info "Sending file #{file.path}" unless logger.nil? - render :status => options[:status], :text => file.read - end + self.status = options[:status] || 200 + self.content_type = options[:content_type] if options.key?(:content_type) + self.response_body = file else old_send_file(file, options) end