Skip to content

Instantly share code, notes, and snippets.

@STRd6
Created June 22, 2013 02:20
Show Gist options
  • Save STRd6/5835574 to your computer and use it in GitHub Desktop.
Save STRd6/5835574 to your computer and use it in GitHub Desktop.
Save data to your local filesystem by posting to your webserver.
require "sinatra"
configure do
set :root, "."
set :public_folder, "."
end
# Any post to /save will write data to the path provided.
post '/save' do
data = params["data"]
path = params["path"]
# Ensure directory exists
FileUtils.mkdir_p File.dirname(path)
File.open(path, 'w') do |file|
file.write(data)
end
200
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment