DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Emad has posted 58 posts at DZone. View Full User Profile

Uplaod files and images from you android to your desktop/laptop

03.24.2014
| 2051 views |
  • submit to reddit
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
require 'sinatra'

set :port, 3000
set :environment, :production

get '/' do
	<<-EOT
<html><head>
	</head><body style="padding:0px;margin:0px;">
	<form action="/upload" method="post" enctype="multipart/form-data" >
		Choose files <input type="file" name="files[]" multiple>
		<input type="submit" value="Upload" />
	</form>
</body></html>
EOT
end

post '/upload' do
	params['files'].each do |f|
		tempfile = f[:tempfile]
		filename = f[:filename]
		FileUtils.copy(tempfile.path, "./#{filename}")
	end
	redirect '/'
end