Re-factoring a CURL request to Ruby's RestClient
Posted
by
user94154
on Stack Overflow
See other posts from Stack Overflow
or by user94154
Published on 2011-11-11T17:01:36Z
Indexed on
2011/11/23
9:50 UTC
Read the original article
Hit count: 329
I'm having trouble translating this CURL request into Ruby using RestClient:
system("curl --digest -u #{@user}:#{@pass} '#{@endpoint}/#{id}' --form image_file=@'#{path}' -X PUT")
I keep getting 400 Bad Request
errors. As far as I can tell, the request does get properly authenticated, but hangs up from the file upload part. Here are my best attempts, all of which get me those 400 errors:
resource = RestClient::Resource.new "#{@endpoint}/#{id}", @user, @pass
#attempt 1
resource.put :image_file => File.new(path, 'rb'), :content_type => 'image/jpg'
#attempt 2
resource.put File.read(path), :content_type => 'image/jpg'
#attempt 3
resource.put File.open(path) {|f| f.read}, :content_type => 'image/jpg'
© Stack Overflow or respective owner