0

I am trying to send a file via a HTTP PUT request. Curl allows this like:

http://curl.haxx.se/docs/httpscripting.html#PUT

What's the correct way of doing this with Typheous?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
scientistician
  • 101
  • 1
  • 3

2 Answers2

1

FWIW this is what I think was the complete (but not necessarily shortest) answer to the question.

Curl allows the uploading of files w/ PUT; the invocation is:

$ curl --upload-file filename url 

where url may be something like:

http://someurl/script.php?var=value&anothervar=val&...

Typhoeus provides the same functionality, but the right way to pass url, params and their values as well as the file body is buried in the ethon docs:

request = Typhoeus::Request.new(
    url, :method => :put, :params => params_hash,
    :body => File.open(filename) { |io| io.read })

Use request object to get response, etc.

scientistician
  • 101
  • 1
  • 3
0

You couldn't have looked very hard:

Examples:

Make put request.

   Typhoeus.put("www.example.com")

Parameters:

base_url (String) — The url to request.
options (options) (defaults to: {}) — The options.

Options Hash (options):

:params (Hash) — Params hash which is attached to the base_url.
:body (Hash) — Body hash which becomes a PUT request body.

http://rubydoc.info/github/typhoeus/typhoeus/Typhoeus/Request/Actions#put-instance_method

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • There is an example of how to POST files but not one on how to PUT. I expected the put method to take the same options like post, so I could pass in the file as a member of the :body hash, but that is not what I end up with. – scientistician Apr 21 '14 at 16:07
  • You failed to mention any of that in your question. Perhaps telling us what you've tried, and why it didn't work, would help? Show sample code that demonstrates the problem. – the Tin Man Apr 21 '14 at 16:11
  • You might also find the related post "[PUT vs POST in REST](http://stackoverflow.com/questions/630453/put-vs-post-in-rest?rq=1)" useful. – the Tin Man Apr 21 '14 at 16:12
  • The problem is quite simple: send a file via PUT. Curl allows it as linked in the question. Using Typheous, via put, I end up with a PUT body that contains the stringification of my option hash, i.e., something like: ["filename", "application/octet-stream", "/path/to/filename"]. – scientistician Apr 21 '14 at 16:16
  • As I said, it should be mentioned in your question. Don't leave a trail of comments that slowly define your question's scope strewn through the answers. The better your question is asked, the faster we can help you find a solution. As is, you're going to make people trying to help you read every comment, and decipher the order they were posted, to figure out what you've done. – the Tin Man Apr 21 '14 at 16:19