1

我已尝试执行以下操作,但 Web 服务不是 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
4

1 回答 1

1

得到了答案:使用 I/O 以字符串形式流式传输,而不是使用 File.new....

:file => IO.read("#{@postalcard.postalimage.path}")
于 2010-06-02T04:42:48.467 回答