-
-
Save arvind02/f1475f545add2f80ea389fc9a066e400 to your computer and use it in GitHub Desktop.
Ruby rest-client file upload as multipart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rest-client' | |
RestClient.get(url, headers={}) | |
RestClient.post(url, payload, headers={}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestClient.get 'http://example.com/resource' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestClient.post '/data', {:foo => 'bar', :multipart => true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request = RestClient::Request.new( | |
:method => :post, | |
:url => '/data', | |
:user => @sid, | |
:password => @token, | |
:payload => { | |
:multipart => true, | |
:file => File.new("/path/to/image.jpg", 'rb') | |
}) | |
response = request.execute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response = RestClient.post( | |
'/data', | |
{ | |
:name => 'daipresents', | |
:user_image => File.new('sample.jpg', 'rb') | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request = RestClient::Request.new( | |
:method => :post, | |
:url => '/data', | |
:payload => { | |
:name => 'daipresents', | |
:user_image => File.new('sample.jpg', 'rb') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestClient.post( url, | |
{ | |
:transfer => { | |
:path => '/foo/bar', | |
:owner => 'that_guy', | |
:group => 'those_guys' | |
}, | |
:upload => { | |
:file => File.new(path, 'rb') | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RestClient.get 'https://user:password@example.com/private/resource', {accept: :json} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment