I have been using a RestClient request as such:
response = RestClient.post server_url, post_params, accept: :json
Which has been working fine. But I need to increase the timeout as it's not completing every now and then while the server is performing the upload.
I have researched and found that the only solution is to change the syntax to something like:
response = RestClient::Request.execute(:method => :post, :url => server_url, post_params, :timeout => 9000000000)
however, I don't seem to be able to pass the hashmap of parameters ('post_params'
) like i was able to in the previous call. how should I write the request so that 'post_params'
is included. It's a complex hashmap, so i can't augment it or get rid of it.
Help is much appreciated.
The data you send is called a payload, so you need do specify it as payload:
response = RestClient::Request.execute(:method => :post, :url => server_url, :payload => post_params, :timeout => 9000000, :headers => {:accept => :json})
Also, you may want to use a shorter timeout, otherwise there is a chance you get a Errno::EINVAL: Invalid argument.
the data you send is in payload when we try to use rest_client.post or any method like get,put what rest_client do is
def self.post(url, payload, headers={}, &block)
Request.execute(:method => :post, :url => url, :payload => payload,
:headers => headers, &block)
end
so like we want to execute
response = RestClient.post api_url,
{:file => file, :multipart => true },
{ :params =>{:foo => 'foo'} #query params
so in the execute command will take take {:file => file, :multipart => true }
as payload and { :params =>{:foo => 'foo' } }
as header so
for passing all these you need
response= RestClient::Request.execute(:method => :post,
:url => api_url,
:payload => {:file => file, :multipart => true },
:headers => { :params =>{:foo => 'foo'}},
:timeout => 90000000)
this should do
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With