1

I'm currently trying to send multiple files to a webservice (and to proceed, depending on the response afterwards, but that's not where I am at yet). The following code sends one file:

 def show
   ...
   conn = Faraday.new(:url => 'webservice.abc' ) do |faraday|
     faraday.request :multipart
     faraday.adapter :net_http
   end
   payload = { :files => Faraday::UploadIO.new("#{Rails.root}/fileone.xml", 'application/xml') }
   conn.post 'http://webservice.abc', payload
   @output = response.body
end

And now I'm stuck, trying to find a way to send 2 (or more) files at once, which is necessary as the purpose of the webservice is to compare these. It seems that when I put them into an array, they can't be handled with. So what I'm looking for is the way to "bundle" the files in order to POST them afterwards (as said before- it works with one file)

TYIA for your time

  • Have you tried `payload = { :file1 => Faraday::UploadIO.new("#{Rails.root}/fileone.xml", 'application/xml'), :file2 => Faraday::UploadIO.new("#{Rails.root}/filetwo.xml", 'application/xml') }` – Deepak Kumar Aug 01 '13 at 04:19

1 Answers1

0

Thanks Deepak,

gave me a hint into the right direction. Should be :files[i], though- so the payload line from the question reads:

payload = { :files[0] => Faraday::UploadIO.new("#{Rails.root}/fileone.xml", 'application/xml'), 
            :files[1] => Faraday::UploadIO.new("#{Rails.root}/filetwo.xml", 'application/xml')}