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, content_disposition = nil) ⇒ Object

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

I think we should remove this from the default helpers and move it into Ramaze, the functionality is almost never used, the naming is ambigous, and it doesn’t use the send_file capabilities of frontend servers.

So for now, I’ll mark it for deprecation



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/innate/helper/send_file.rb', line 12

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

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

  throw(:respond, response)
end