I understand how to make an http request using basic authentication with Ruby\'s rest-client
response = RestClient::Request.new(:method => :get, :url => @b
RestClient API seems to have changed. Here's the latest way to upload a file using basic auth:
response = RestClient::Request.execute(
method: :post,
url: url,
user: 'username',
password: 'password',
timeout: 600, # Optional
payload: {
multipart: true,
file: File.new('/path/to/file, 'rb')
}
)
How about using a RestClient::Payload
with RestClient::Request
...
For an example:
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
Here is an example with a file and some json data:
require 'rest-client'
payload = {
:multipart => true,
:file => File.new('/path/to/file', 'rb'),
:data => {foo: {bar: true}}.to_json
}
r = RestClient.post(url, payload, :authorization => token)
The newest best way may be that: the link is enter link description here
RestClient.post( url,
{
:transfer => {
:path => '/foo/bar',
:owner => 'that_guy',
:group => 'those_guys'
},
:upload => {
:file => File.new(path, 'rb')
}
})