I have a curl request of the below that works but when I translate it into the below I get the following error what is wrong with this header - I feel I’ve done it every possible way – any advice is welcomed. Is there an alternative hex package that will work with reasonable documentation.
url = "https://content.dropboxapi.com/2/files/download"
header = [ {"Authorization", "Bearer #{token}"}, {"Dropbox-API-Arg", "{\"path\": \"/dropboxtest/image.jpg\"}"} ]
HTTPoison.post(url=url, header=header)
** (ArgumentError) argument error
:erlang.iolist_to_binary([{"Authorization", "Bearer <removed>"}, {"Dropbox-API-Arg", "{\"path\": \"/dropboxtest/image.jpg\"}"}])
(hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney_request.erl:348: :hackney_request.handle_body/4
(hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney_request.erl:83: :hackney_request.perform/2
(hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney.erl:376: :hackney.send_request/2
(httpoison) lib/httpoison/base.ex:796: HTTPoison.Base.request/6
Hi,
Can you explain what are you trying to achieve?
Reason for question: Because there is a possibility that your current approach may not be the best way to do it.
opsb
December 7, 2019, 11:19am
3
Headers are the third parameter, see https://hexdocs.pm/httpoison/HTTPoison.html#post/4 . If you don’t want to post a body then pass nil as the second argument.
HTTPoison.post(url, nil, header)
3 Likes
That is a curious way to pass your parameters, why not simply (url, header)?
2 Likes
Nicd
December 7, 2019, 12:58pm
5
Looks like OP has Elixir confused with Python. Elixir doesn’t have named arguments like that.
And it still works, but it’s strange in Elixir world
Trying to download a file from a dropbox folder. The below curl works. It wants a custom header “Dropbox-API-Arg” with the path to the file included in the post.
curl -X POST https://content.dropboxapi.com/2/files/download
–header "Authorization: Bearer "
–header “Dropbox-API-Arg: {“path”: “/dropboxtest/image.jpg”}” -O image.jpg
1 Like
NobbZ
December 7, 2019, 6:02pm
8
As others already have said, the 2nd parameter of HTTPoison.post/4
is the body, If you do not want to send a body, then you need to set it to nil
explicitely:
HTTPoison.post(url, nil, header)
Thanks for the clarification @chavenor . But i am confused why you would use HTTPoison to do this?
Don’t you need the file(s) in a user interface in a front-end?
Woudln’t something like this be better
I saw that package. Choose not to go with it because it said it wasn’t production-ready.
We have a shared folder in which images are auto-uploaded to.
We want to fetch those images and then transfer them to the cloud as well as create an Amazon Turk hit for some work. We’ll fetch that finished Turk job later and post it to a db that reports are run off of.
url = "https://content.dropboxapi.com/2/files/download"
header = [ {"Authorization", "Bearer #{token}"}, {"Dropbox-API-Arg", "{\"path\": \"/dropboxtest/image.jpg\"}"} ]
HTTPoison.post(url, nil, header)
HTTPoison.post(url, nil, header)
** (CaseClauseError) no case clause matching: nil
(hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney_request.erl:318: :hackney_request.handle_body/4
(hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney_request.erl:83: :hackney_request.perform/2
(hackney) /Users/casey/Dropbox/BOS Sales LLC/backyardmicro/projects/k-9dryers/software/connectk9/deps/hackney/src/hackney.erl:376: :hackney.send_request/2
(httpoison) lib/httpoison/base.ex:796: HTTPoison.Base.request/6
1 Like
NobbZ
December 9, 2019, 5:26pm
11
Then it’s probably an empty list or binary for the body… I just assumed the former call was correct, but now I at least skimmed the docs
This worked!
url = "https://content.dropboxapi.com/2/files/download"
header = [ {"Authorization", "Bearer #{token}"}, {"Dropbox-API-Arg", "{\"path\": \"/dropboxtest/image.jpg\"}"} ]
HTTPoison.post(url, [], header)
1 Like