2011-02-28 84 views
5

您好我見過httparty但我沒有主意,如何實現有模型文件的許多例子,但它paramater可以使用上傳的視頻文件如何上傳視頻文件,httparty

+0

有你看了[httparty例子(https://github.com/jnunemaker/httparty/tree/master/例如)在httparty回購? – idlefingers 2011-02-28 13:21:29

回答

6

HTTMultiParty通過發佈多部分MIME文檔支持文件上傳。它包裝HTTParty,以便以相同的方式使用它。對於該文件,只需提供一個File對象。自述例如:

require 'httmultiparty' 
class SomeClient 
    include HTTMultiParty 
    base_uri 'http://localhost:3000' 
end 

response = SomeClient.post('/', :query => { 
    :foo  => 'bar', 
    :somefile => File.new('README.md') 
}) 
1

通過使用RESTClient實現創業板,我們可以輕鬆地處理文件上傳,但要確保你安裝其他客戶端的寶石。

而且我還附上郵遞員示例請求的截圖。

並在控制器像下面的代碼,

res = RestClient::Request.execute(
     method: :post, 
     url: "http://www.your_url.com", 
     payload: params, 

     headers: { 
      'Content-Type' => "multipart/form-data", 
      Authorization: "some_key", 
      :Accept => "*/*" 
     } 

) 

enter image description here