Created
June 30, 2009 04:53
-
-
Save zlu/138002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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