Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPoison upload file

Tags:

elixir

is there any tutorial how to upload local files with HTTPoison.post ? opening a file

{:ok, file} = File.open "README.md"
HTTPoison.post("#{url}", file, headers)

this is for dropbox integration using upload functionality

curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer " \
--header "Dropbox-API-Arg: {\"path\":\"/Homework/math/Matrices.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @local_file.txt

the problem is how to send —data-binary file.

Any ideas?

Thanks

like image 491
sger Avatar asked Oct 22 '25 05:10

sger


1 Answers

I believe the equivalent of curl's --data-binary would be to use {:file, path} as the body, as documented in Hackney's README.md.

This should send the same request as your curl example:

HTTPoison.post("https://content.dropboxapi.com/2/files/upload",
               {:file, "local_file.txt"},
               [{"Authorization", "Bearer "}, ...])
like image 63
Dogbert Avatar answered Oct 27 '25 02:10

Dogbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!