Method: Sinatra::Helpers#send_file
- Defined in:
- lib/sinatra/base.rb
- (Object) send_file(path, opts = {})
Use the contents of the file at path as the response body.
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/sinatra/base.rb', line 264 def send_file(path, opts={}) if opts[:type] or not response['Content-Type'] content_type opts[:type] || File.extname(path), :default => 'application/octet-stream' end if opts[:disposition] == 'attachment' || opts[:filename] opts[:filename] || path elsif opts[:disposition] == 'inline' response['Content-Disposition'] = 'inline' end last_modified opts[:last_modified] if opts[:last_modified] file = Rack::File.new nil file.path = path result = file.serving env result[1].each { |k,v| headers[k] ||= v } headers['Content-Length'] = result[1]['Content-Length'] halt opts[:status] || result[0], result[2] rescue Errno::ENOENT not_found end |