开发者

Can I use rest-client to POST a binary file to HTTP without multipart?

I have tried to do the following, but the web-service is NOT REST and does not take multi-part. What do I do in order to POST the image?

@response = RestCl开发者_StackOverflow中文版ient.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


Got the answer: use I/O to stream as a string instead of using File.new....

:file => IO.read("#{@postalcard.postalimage.path}")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜