Search code examples
ruby-on-railshttpclientmultipart

HTTPClient post from string


I'm trying to integrate Zoho viewer:

clnt = HTTPClient.new
@zoho_link = clnt.post('http://viewer.zoho.com/api/view.do', {:apikey => 'd4a361ce621000000000000', :file => File.new('/home/jon/Desktop/data.csv')})

I already have data in a variable and I want to pass it as a multipart post parameter. How can I make this work without creating a data.csv file?

Thanks!


Solution

  • Use StringIO thusly:

    require 'stringio'
    clnt = HTTPClient.new
    @zoho_link = clnt.post('http://viewer.zoho.com/api/view.do', {:apikey => 'd4a361ce621000000000000', :file => StringIO.new(your_string)})