downloading of files from Dropbox using cli-http

332 views
Skip to first unread message

Johannes

unread,
Jun 25, 2018, 8:38:12 AM6/25/18
to Clojure
Hi,

I am trying to download a file from Dropbox which I can get with the Http request:

POST /2/files/download Host: https://content.dropboxapi.com User-Agent: api-explorer-client Authorization: Bearer QfCCK... Dropbox-API-Arg: {"path":"/log.txt"}

or the curl request looks like that:

curl -X POST https://content.dropboxapi.com/2/files/download \ --header 'Authorization: Bearer QfCCK...' \ --header 'Dropbox-API-Arg: {"path":"/log.txt"}'

If I try the following using cli-http in a Clojurescript repl:

(go (let [response (<! (http/post "https://content/dropboxapi.com/2/files/download" {:headers {"authorization" "Bearer QfCCK..." "Dropbox-API-Arg" "{\"path\":\"/log.txt\"}"} }))] (println response)))

I get

#object[cljs.core.async.impl.channels.ManyToManyChannel]

{:status 0, :success false, :body , :headers {}, :trace-redirects [https://content/dropboxapi.com/2/files/download https://content/dropboxapi.com/2/files/download], :error-code :http-error, :error-text  [0]}


I cannot figure out where my mistake is. Any help?


Johannes

Thomas

unread,
Jun 25, 2018, 11:09:58 AM6/25/18
to Clojure
try and do a curl -v and see what it really does under the covers as there might be a redirect

Good luck,
Thomas

Johannes

unread,
Jun 25, 2018, 11:42:00 AM6/25/18
to Clojure

That's the result:



curl -vX POST https://content.dropboxapi.com/2/files/download   --header 'Authorization: Bearer QfCCK...'   --header 'Dropbox-API-Arg: {"path":"/log.txt"}'>x.txt 

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 2620:100:6022:8::a27d:4208...

* TCP_NODELAY set

* Connected to content.dropboxapi.com (2620:100:6022:8::a27d:4208) port 443 (#0)

* ALPN, offering h2

* ALPN, offering http/1.1

* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

* successfully set certificate verify locations:

*   CAfile: /etc/ssl/cert.pem

  CApath: none

* TLSv1.2 (OUT), TLS handshake, Client hello (1):

} [512 bytes data]

* TLSv1.2 (IN), TLS handshake, Server hello (2):

{ [106 bytes data]

* TLSv1.2 (IN), TLS handshake, Certificate (11):

{ [3302 bytes data]

* TLSv1.2 (IN), TLS handshake, Server key exchange (12):

{ [333 bytes data]

* TLSv1.2 (IN), TLS handshake, Server finished (14):

{ [4 bytes data]

* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):

} [70 bytes data]

* TLSv1.2 (OUT), TLS change cipher, Client hello (1):

} [1 bytes data]

* TLSv1.2 (OUT), TLS handshake, Finished (20):

} [16 bytes data]

* TLSv1.2 (IN), TLS change cipher, Client hello (1):

{ [1 bytes data]

* TLSv1.2 (IN), TLS handshake, Finished (20):

{ [16 bytes data]

* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384

* ALPN, server accepted to use http/1.1

* Server certificate:

*  subject: C=US; ST=California; L=San Francisco; O=Dropbox, Inc; OU=Dropbox Ops; CN=content.dropboxapi.com

*  start date: Feb  7 00:00:00 2017 GMT

*  expire date: Feb 12 12:00:00 2020 GMT

*  subjectAltName: host "content.dropboxapi.com" matched cert's "content.dropboxapi.com"

*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA

*  SSL certificate verify ok.

> POST /2/files/download HTTP/1.1

> Host: content.dropboxapi.com

> User-Agent: curl/7.54.0

> Accept: */*

> Authorization: Bearer QfCCK...

> Dropbox-API-Arg: {"path":"/log.txt"}

  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0< HTTP/1.1 200 OK

< Server: nginx

< Date: Mon, 25 Jun 2018 15:29:43 GMT

< Content-Type: application/octet-stream

< Content-Length: 199945

< Connection: keep-alive

< accept-ranges: bytes

< etag: W/"2a575a545945"

< pragma: no-cache

< cache-control: no-cache

< original-content-length: 199945

< dropbox-api-result: {"name": "log.txt", "path_lower": "/log.txt", "path_display": "/log.txt", "id": "id:hNm0VDys4tAAAAAAAAAADA", "client_modified": "2018-06-24T21:53:42Z", "server_modified": "2018-06-24T21:53:43Z", "rev": "2a575a545945", "size": 199945, "content_hash": "4366a79928e7a4e7db9da0c7b05c4c76fa016c0f5886fa106b47fd2e7a960db9"}

< X-Server-Response-Time: 765

< X-Dropbox-Request-Id: 3301820ab86536937d476e8ea895ff22

< X-Robots-Tag: noindex, nofollow, noimageindex

{ [15632 bytes data]

100  195k  100  195k    0     0   156k      0  0:00:01  0:00:01 --:--:--  156k

* Connection #0 to host content.dropboxapi.com left intact


The has been downloaded successfully.

Thomas

unread,
Jun 26, 2018, 3:37:56 AM6/26/18
to Clojure
I have no idea what could be wrong here... sorry.

Thomas

On Monday, 25 June 2018 14:38:12 UTC+2, Johannes wrote:

Immo Heikkinen

unread,
Jun 26, 2018, 5:54:22 AM6/26/18
to clo...@googlegroups.com
You have slash instead of dot after "content" in the url: "https://content/dropboxapi.com/2/files/download"

Br,
Immo



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johannes

unread,
Jun 26, 2018, 6:36:10 AM6/26/18
to Clojure
Thanks Immo, what a silly mistake!

But after having corrected it, I get the same result as before:

(go (let [response (<! (http/post "https://content.dropboxapi.com/2/files/download"
                                  {:headers {"authorization" "Bearer QfCCK..."
                                             "Dropbox-API-Arg" "{\"path\":\"/log.txt\"}"}         
                                   }))] 
      (println response)))

==>

#object[cljs.core.async.impl.channels.ManyToManyChannel]

{:status 0, :success false, :body , :headers {}, :trace-redirects [https://content.dropboxapi.com/2/files/download https://content.dropboxapi.com/2/files/download], :error-code :http-error, :error-text  [0]}

Immo Heikkinen

unread,
Jun 26, 2018, 6:51:14 AM6/26/18
to clo...@googlegroups.com
Have you checked JS console in your browser, does is show any errors?

Br,
Immo

Johannes

unread,
Jun 26, 2018, 7:28:39 AM6/26/18
to Clojure
Yes, there was an authorisation problem, I have to include :with-credentials? false. Additionally the "Content-Type" has to be specified in the headers. The following call works now:
(go (let [response (<! (http/post "https://content.dropboxapi.com/2/files/download"
                                  {:with-credentials? false
                                   :headers {"authorization" "Bearer QfCC..."
                                             "Dropbox-API-Arg" "{\"path\":\"/log.txt\"}"
                                             "Content-Type" "text/plain; charset=utf-8"}         
                                   }))] 
      (println response)))

Thanks for your help!

Johannes
Reply all
Reply to author
Forward
0 new messages