Skip to content

Instantly share code, notes, and snippets.

@yyyyyyuanfei
Created April 5, 2012 09:11
Show Gist options
  • Select an option

  • Save yyyyyyuanfei/2309394 to your computer and use it in GitHub Desktop.

Select an option

Save yyyyyyuanfei/2309394 to your computer and use it in GitHub Desktop.
sinatra upload file
require 'sinatra'
post '/upload' do
unless params[:file] &&
(tmpfile = params[:file][:tempfile]) &&
(name = params[:file][:filename])
@error = "No file selected"
return haml(:upload)
end
STDERR.puts "Uploading file, original name #{name.inspect}"
while blk = tmpfile.read(65536)
# here you would write it to its final location
STDERR.puts blk.inspect
end
"Upload complete"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment