Last active
May 22, 2021 03:01
-
-
Save daipresents/528891497cc6e89f5c06e597a8dcc2e1 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:[email protected]/private/resource', {accept: :json} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment