在一个 ruby 项目中,我试图将图像发送到侦听 POSTS 请求的服务器。我想避免使用额外的必要宝石。我正在使用 ruby 1.9.3 并且服务器不支持 net/http Multiport 和以下代码:
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)
崩溃并显示以下错误消息:
http.rb:1932:in `send_request_with_body': undefined method `bytesize' for #<File:0x007ffdcd335270> (NoMethodError)
虽然以下在 bash 中成功:
curl -i -X POST --data-binary @./output.jpg -H 'X-ClientId: ##..##' -H 'X-ClientSecret: ##..##' http:/someserver/output.jpg
知道出了什么问题吗?
提前致谢