我尝试过以下操作,但是网络服务不是REST,也不是多部分。如何发布图像我该怎么办?
@response = RestClient.post('http://www.postful.com/service/upload',
{:upload => {
:file => File.new("#{@postalcard.postalimage.path}",'rb')
}
},
{"Content-Type" => @postalcard.postalimage.content_type,
"Content-Length" => @postalcard.postalimage.size,
"Authorization" => 'Basic xxxxxx'
} # end headers
) #close arguments to Restclient.post
答案 0 :(得分:1)
得到答案:使用I / O作为字符串流而不是使用File.new ....
:file => IO.read("#{@postalcard.postalimage.path}")