2010-05-28 37 views
1

我試圖做到以下幾點,但是Web服務不是REST,並且不需要多個部分。我要怎麼做才能發佈圖片?我可以使用rest-client將一個二進制文件發送到沒有multipart的HTTP嗎?

@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 

回答

1

得到了答案:使用I/O流來作爲一個字符串,而不是使用File.new ....

:file => IO.read("#{@postalcard.postalimage.path}") 
相關問題