Last Updated: February 25, 2016
·
1.531K
· rshetty

MultiPart POST with Image Upload Script

require 'rest_client'


 @image1 =  { :file =>  File.new("spec/support/labrador.jpg") }

 @images = [ {@image1} ]

 @params = {:name => "Test", :description => "aaaa",
                          :website => "http://something.com",
                          :unlocked_time => "00:30:00", 
                          :company_id => "1",
                          :image_url => "aaaaaa",
                          :images_attributes => @images
         }



url = "http://localhost:3000/api/products"


begin
  response = RestClient.post url,{ :product => @params }
  p response.to_str
  rescue => e
   p e.response
end