Skip to content

Instantly share code, notes, and snippets.

@vagmi
Forked from dhruvasagar/gist:1532564
Created December 29, 2011 07:30
Show Gist options
  • Save vagmi/1532620 to your computer and use it in GitHub Desktop.
Save vagmi/1532620 to your computer and use it in GitHub Desktop.
Sinatra File Server for serving Videos & Images
$:.unshift File.expand_path("#{File.dirname(__FILE__)}")
APP_ROOT = File.expand_path(File.dirname(__FILE__))
puts APP_ROOT
require 'sinatra'
get '*' do
rpath=File.join(APP_ROOT,params[:splat][0][1..-1])
mimetype = `file -Ib #{rpath}`.gsub(/\n/,"")
puts "serving #{rpath} with mimetype #{mimetype}"
send_file rpath, :stream=>true, :type=>mimetype, :disposition=>:inline
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment