Skip to content

Instantly share code, notes, and snippets.

@gavinheavyside
Created November 3, 2009 20:09
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save gavinheavyside/225381 to your computer and use it in GitHub Desktop.
Save gavinheavyside/225381 to your computer and use it in GitHub Desktop.
Trivial file upload service using Sinatra
require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
post '/:name/:filename' do
userdir = File.join("files", params[:name])
FileUtils.mkdir_p(userdir)
filename = File.join(userdir, params[:filename])
datafile = params[:data]
# "#{datafile[:tempfile].inspect}\n"
File.open(filename, 'wb') do |file|
file.write(datafile[:tempfile].read)
end
"wrote to #{filename}\n"
end
@benwr
Copy link

benwr commented Feb 13, 2011

How would that call to curl be replicated in an html form?

@gavinheavyside
Copy link
Author

Take a look at aliem's fork, it seems to have an html example: https://gist.github.com/428783

@benwr
Copy link

benwr commented Feb 14, 2011

Awesome, thanks! Should have searched a bit harder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment