Skip to content

Instantly share code, notes, and snippets.

@flagranterror
Created February 21, 2012 15:34
Show Gist options
  • Save flagranterror/1877047 to your computer and use it in GitHub Desktop.
Save flagranterror/1877047 to your computer and use it in GitHub Desktop.
Sinatra basic file uploader
#!/usr/bin/env ruby
require 'sinatra'
require 'haml'
get "/upload" do
haml :upload
end
post "/upload" do
file_name = settings.root + "/public/uploads/" + params[:file][:filename]
File.open(file_name, "w") { |f| f.write(params[:file][:tempfile]) }
"Success! " + haml("%a{:href => '' } Upload ") + "something else."
end
__END__
@@ upload
%html
%body
%form{:action => "", :method => "post", :enctype => 'multipart/form-data'}
%label{:for => 'file'}Choose a file:
%br
%input{:type => "file", :name => "file"}
%br
%input{:type => "submit", :value => "upload"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment