Module: SendS3File

Included in:
ActionController::Base
Defined in:
lib/send_s3_file.rb,
lib/send_s3_file/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Instance Method Details

#send_s3_file(s3_object, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/send_s3_file.rb', line 9

def send_s3_file s3_object, options = {}
  headers.merge!(
      'Content-Type'              => build_content_type(options),
      'Content-Disposition'       => build_disposition(options),
      'Content-Transfer-Encoding' => 'binary',
      'Content-Length' => s3_object.content_length
  )

  render :status => options[:status], :text => Proc.new {|response, output|
    logger.info "Streaming file from s3 #{s3_object.bucket} #{s3_object.key}" unless logger.nil?
    s3_object.read do |chunk|
      output.write(chunk)
    end
    logger.info "Done Streaming file from s3 #{s3_object.bucket} #{s3_object.key}" unless logger.nil?
  }
end