Skip to content

Instantly share code, notes, and snippets.

@honnix
Created November 25, 2013 21:33
Show Gist options
  • Save honnix/7649280 to your computer and use it in GitHub Desktop.
Save honnix/7649280 to your computer and use it in GitHub Desktop.
upload file in sinatra
require 'sinatra'
require 'haml'
# Handle GET-request (Show the upload form)
get "/upload" do
haml :upload
end
# Handle POST-request (Receive and save the uploaded file)
post "/upload" do
File.open('uploads/' + params['myfile'][:filename], "w") do |f|
f.write(params['myfile'][:tempfile].read)
end
return "The file was successfully uploaded!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment