-
-
Save vagmi/1532620 to your computer and use it in GitHub Desktop.
Sinatra File Server for serving Videos & Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.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