On a ruby project I am trying to send a image to a server listening to POSTS requests. I would like to avoid using extra necessary gems. I am using ruby 1.9.3 and net/http Multiport is not supported by the server and the following code:
require 'net/http'
require "uri"
image = File.open(image.path, 'r')
url = URI("http://someserver/#{image_name}")
req = Net::HTTP.new(url.host, url.port)
Net::HTTP.new(url.host, url.port)
headers = {"X-ClientId" => client_id, "X-ClientSecret" => client_secret, "Content-Type" => "image/jpeg"}
response, body = req.post(url.path, image, headers)
crashes with the following error message:
http.rb:1932:in `send_request_with_body': undefined method `bytesize' for #<File:0x007ffdcd335270> (NoMethodError)
While the following succeed in bash:
curl -i -X POST --data-binary @./output.jpg -H 'X-ClientId: ##..##' -H 'X-ClientSecret: ##..##' http:/someserver/output.jpg
Any idea what is going wrong?
Thanks in advance