Module: Innate::Helper::SendFile

Defined in:
lib/innate/helper/send_file.rb

Instance Method Summary collapse

Instance Method Details

#send_file(filename, content_type = nil) ⇒ Object

Not optimally performing but convenient way to send files by their filename.



6
7
8
9
10
11
12
13
14
15
# File 'lib/innate/helper/send_file.rb', line 6

def send_file(filename, content_type = nil)
  content_type ||= Rack::Mime.mime_type(::File.extname(filename))

  response.body = ::File.readlines(filename, 'rb')
  response['Content-Length'] = ::File.size(filename).to_s
  response['Content-Type'] = content_type
  response.status = 200

  throw(:respond, response)
end