Created
November 5, 2017 10:56
-
-
Save mvasin/7f3c537305993e2357bbb9ba7d77f88c to your computer and use it in GitHub Desktop.
The simplest code possible to upload a file to a server
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
# uploads folder must exist. | |
require 'roda' | |
class App < Roda | |
route do |r| | |
r.root do | |
<<-HEREDOC | |
<html> | |
<body> | |
<form method="post" enctype="multipart/form-data"> | |
<input type="hidden" name="file"> | |
<input type="file" name="file"> | |
<input type="submit"> | |
</form> | |
</body> | |
</html> | |
HEREDOC | |
end | |
r.post '' do | |
File.new('uploads/' + r.params['file'][:filename], 'w') do | |
r.params['file'][:tempfile] | |
end | |
"Thanks for uploading #{r.params['file'][:filename]}!" | |
end | |
r.is 'presign' do | |
r.run Shrine.presign_endpoint(:cache) | |
end | |
end | |
end | |
run App.freeze.app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment