Created
March 28, 2017 04:58
-
-
Save dchymko/4c1f50d23d9c7199af9e1a288bdb5ded to your computer and use it in GitHub Desktop.
File upload in Sinatra for Lighthouse
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
get '/upload' do | |
erb (:upload) | |
end | |
post '/upload' do | |
if params[:file] | |
filename = params[:file][:filename] | |
file = params[:file][:tempfile] | |
file_dir = File.join(settings.public_folder, 'files') | |
File.open(File.join(file_dir, filename), 'wb') do |f| | |
f.write file.read | |
end | |
end | |
"file uploaded" | |
end |
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
<html> | |
<body> | |
<h1> Search</h1> | |
<form action='/upload' enctype="multipart/form-data" method='POST'> | |
<input name="file" type="file" /> | |
<input type="submit" value="Upload" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment