Created
November 25, 2013 21:33
-
-
Save honnix/7649280 to your computer and use it in GitHub Desktop.
upload file in sinatra
This file contains hidden or 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 '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