Skip to content

Instantly share code, notes, and snippets.

@zlu
Created June 30, 2009 04:53
Show Gist options
  • Save zlu/138002 to your computer and use it in GitHub Desktop.
Save zlu/138002 to your computer and use it in GitHub Desktop.
#Sinatra server
require 'rubygems'
require 'sinatra'
post '/upload' do
filename = "./uploaded/" + Time.now.to_i.to_s + ".gsm"
FileUtils.mv params[:data][:tempfile].path, filename
"Received #{File.size filename} bytes and saved as #{filename} for user #{params[:user_id]}"
end
require 'rubygems'
require 'curb'
url = 'http://localhost:4567/upload'
c = Curl::Easy.new url
c.multipart_form_post = true
c.http_post Curl::PostField.file('data', './to_upload/tt-monkeys.gsm'), Curl::PostField.content('user_id', '1')
p c.body_str
#Returns
ruby upload_client.rb
"Received 26697 bytes and saved as ./uploaded/1246337343.gsm for user 1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment