Skip to content

Instantly share code, notes, and snippets.

@mgamba
Created June 4, 2016 15:49
Show Gist options
  • Select an option

  • Save mgamba/1a263f3344207f0a1f482ae33817df16 to your computer and use it in GitHub Desktop.

Select an option

Save mgamba/1a263f3344207f0a1f482ae33817df16 to your computer and use it in GitHub Desktop.
file uploader because i'm too lazy to figure out how to make my phone talk to my computer
require 'sinatra'
require 'base64'
set :environment, :production
get '/' do
html = '
<form action="run" method="POST" enctype="multipart/form-data">
<input type="file" name="file" accept="image/*" capture="camera">
<input type="submit" value="Upload image">
</form>
'
end
post '/run' do
filename = params[:file][:filename]
file = params[:file][:tempfile]
File.open(filename, 'wb') do |f|
f.write(file.read)
end
redirect to('/')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment