Reputation: 31
I am trying to upload a file in Ruby. Below is a sample of the REST call using curl.
curl --sslv3 -k -v -i -X POST \
-H "Content-Type: multipart/mixed" \
-H "Accept: application/json" \
-H "Cookie: token=ABC; SESSION=13217EBA128F6ABC9E9AD095D602E4AB;" \
-F "metadata=@input_payload_file.json; type=application/json" \
-F "[email protected]; type=image/jpg" \
https://abc.com/attachments.
Can some please give me an equivalent of above in Ruby. I have tried the following, with no success.
$fileitem = File.new('C:\log.txt', 'rb');
$fileinfo = '{"fileName":"log.txt", "resourceName":"log.txt", "description":"Created using REST"}';
response =RestClient::Request.execute(
:method => :post,
:url => $UploadURL,
:headers => {:content_type => 'multipart/mixed', :accept => 'application/json'},
:cookies => {:token=> :"#{cust}",:SESSIONID => :"#{ssid}"},
:payload => $fileinfo,
:myfile => $fileitem
)
Thanks in advance for any guidance.
Ravi..
Upvotes: 1
Views: 3048
Reputation: 31
Finally got the code working. Cleared up the smelly code. Below is the syntax that worked well while posting a multipart/mixed mode data.
response =RestClient::Request.execute(
:method => :post,
:url => uploadURL,
:headers => {:content_type => 'multipart/mixed', :accept => 'application/json'},
:cookies => {:token => cust,:SESSIONID => ssid },
:payload => {:metadata => fileinfo, :content => fileitem, }
)
Upvotes: 2