Upload csv file?

70 views
Skip to first unread message

Boris Kheyfets

unread,
Mar 26, 2016, 12:27:52 PM3/26/16
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Hello,

I'm trying write an analogue of

curl 'https://some.url' -H 'Content-Type: text/csv' --data-binary @file.csv -H 'Authorization: Bearer <TOKEN>'

however I can't figure out how to upload a file. Here's what I've constructed after reading wiki

response = HTTP.post('https://come.url')
    .auth("Bearer #{token}")
    .headers(accept: 'text/csv')

Is it possible to upload a file with http.rb? (there's an example on wiki where a file is uploaded to form. But I don't have a form)

Aleksey Zapparov

unread,
Mar 26, 2016, 1:05:14 PM3/26/16
to Boris Kheyfets, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Hi there!

`Accept` and `Content-Type` headers serve different purpose.
Also you must assign all options before calling HTTP method (post/get/etc):

```
response = HTTP
.auth("Bearer #{token}")
.headers("Content-Type" => "text/csv")
.post("https://some.url")
```
> --
> You received this message because you are subscribed to the Google Groups
> "http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to httprb+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Sincerely yours, Alexey Zapparov
http://ixti.net | +34 677 990 688

Boris Kheyfets

unread,
Mar 26, 2016, 1:33:37 PM3/26/16
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API, kheyf...@gmail.com
Thanks Alexey.

Turns out one should pass csv string as the post message body:

csv = File.read('file.csv')

response = HTTP
  .auth("Bearer #{token}")
  .headers("Content-Type" => "text/csv")
  .post("https://some.url", body: csv)

Aleksey Zapparov

unread,
Mar 26, 2016, 2:00:18 PM3/26/16
to Boris Kheyfets, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Oh. indeed you need to pass request body indeed :D
Reply all
Reply to author
Forward
0 new messages