Created
March 2, 2013 10:43
-
-
Save adimania/5070466 to your computer and use it in GitHub Desktop.
Simple ruby script to upload and view 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
require 'rubygems' | |
require 'sinatra' | |
get '/' do | |
"uploader up" | |
end | |
post '/image' do | |
puts params.inspect | |
File.open("upload-dir/#{params[:id]}", "w") do |f| | |
f.write(params[:photo][:tempfile].read) | |
end | |
end | |
get '/image' do | |
files = "" | |
Dir.foreach("upload-dir/") do |file| | |
files << "<a type='image/png' href='http://example.com/image/view/#{file}'>#{file}</a><br/>" | |
end | |
files | |
end | |
get '/image/:filename' do |filename| | |
send_file "./upload-dir/#{filename}", :filename => filename, :type => 'image/png' | |
end | |
get '/image/view/:filename' do |filename| | |
"<img src='http://example.com/image/#{filename}'>" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment