Skip to content

Commit

Permalink
Rake task using ethon
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-desteffen committed Aug 14, 2015
1 parent 6309fc4 commit 540d1eb
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
task :upload do
task :upload_typhoeus do
require 'typhoeus'

Typhoeus::Config.verbose = true

url = "http://localhost:4567/upload"
headers = {"content-type" => "multipart/form-data"}
body = {
file: File.open((File.dirname(__FILE__) + '/images/pluto.jpg'), 'r')
}
file = File.open((File.dirname(__FILE__) + '/images/pluto.jpg'), 'r')
body = {file: file}

response = Typhoeus.put(url, headers: headers, body: body)
puts "Response code: #{response.code}"
end

task :upload_ethon do
require 'ethon'

url = "http://localhost:4567/upload"
headers = {"content-type" => "multipart/form-data"}
file = File.open((File.dirname(__FILE__) + '/images/pluto.jpg'), 'r')
body = {file: file}

easy = Ethon::Easy.new
easy.http_request(url, :put, body: body, headers: headers)
easy.perform
end

0 comments on commit 540d1eb

Please sign in to comment.