Skip to content

Instantly share code, notes, and snippets.

@pparadis
Created January 26, 2013 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pparadis/4639772 to your computer and use it in GitHub Desktop.
Save pparadis/4639772 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'base64'
require 'haml'
require 'securerandom'
set :static, true
set :public_folder, '/uploads'
get '/' do
haml :index
end
get '/uploads/:file' do |f|
send_file 'uploads/' + f
end
post '/image' do
hostUrl = 'http://' + request.host_with_port()
filePath = 'uploads/' + params['imageName']+SecureRandom.uuid.gsub('-','') + ".png"
File.open(filePath, "wb") do |f|
f.write(Base64.decode64(params['imageData']))
end
return 'http://' + request.host_with_port() + '/' + filePath
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment