Skip to content

Instantly share code, notes, and snippets.

@mvasin
Created November 5, 2017 10:56
Show Gist options
  • Save mvasin/7f3c537305993e2357bbb9ba7d77f88c to your computer and use it in GitHub Desktop.
Save mvasin/7f3c537305993e2357bbb9ba7d77f88c to your computer and use it in GitHub Desktop.
The simplest code possible to upload a file to a server
# 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