Put binary-data with faraday

N

ngw

Hi everyone, I'm trying to use faraday (with default adapter) to put some binary-data to an url.

The request I'm trying to do using curl is:

curl -X PUT https://your_user_token:@api.80legs.com/v2/urllists/name_of_url_list -H "Content-Type: application/octet-stream" --data-binary "[\"http://www.example.com/\", \"http://www.sample.com/\", \"http://www.test.com/\"]" -i

In Faraday I'm setting up the request probably in the wrong way:

require 'tempfile'
tempfile = Tempfile.new(name)
tempfile.write url_list.to_s
conn = Faraday.new(url: "https://#{token}:mad:api.80legs.com/v2/urllists/#{name}") do |faraday|
faraday.request :multipart
faraday.response :logger
end
conn.put do |req|
req.headers['Content-Type'] = 'octet/stream'
req.body = Faraday::UploadIO.new(tempfile, 'octet/stream')
end
tempfile.close

Has someone managed to do something like this before with this gem?

ngw
 
R

Robert Klemme

PS: Maybe you also need to seek after writing to ensure reading starts at the beginning.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,818
Messages
2,569,732
Members
45,691
Latest member
Dick331194

Latest Threads

Top