Wednesday, August 07, 2013

How to do a multipart file upload in ruby

gem install httpclient

 require 'httpclient'  
 require 'uri'  
 # Do multipart file upload with POST  
  httpreq = HTTPClient.new  
  File.open("#{filename}") do |file|  
   body = { 'year' => "#{curyear}", 'tag' => "#{tagname}", 'uploadfile' => file}  
   res = httpreq.post(URI("#{uri}"), body)  
  end  

No comments:

Post a Comment