Help uploading a file using Dropbox API #24

Closed
samrat opened this Issue Dec 26, 2012 · 5 comments

Comments

Projects
None yet
3 participants
@samrat
Contributor

samrat commented Dec 26, 2012

I'm trying to upload a file using the Dropbox API. This is what I've written

(defn upload-file
  "Upload file to Dropbox using PUT.
     root can be either `dropbox` or `sandbox`"
  [consumer access-token-response root remote-path local-path]
  (http/post (str "https://api-content.dropbox.com/1/files_put/" root "/" remote-path)
            {:query-params (make-credentials consumer
                                             access-token-response
                                             :POST
                                             "https://api-content.dropbox.com/1/files/"
                                             nil}
            {:body (clojure.java.io/file local-path)}))

(The full file is at https://bitbucket.org/samrat/jopbox/src/620d223b33b85dbe16b787e653c20d25864f2ca6/src/jopbox/client.clj?at=default#cl-66 )

But that doesn't work(I get a 400 error). Could someone please point me in the right direction, please.

@remleduff

This comment has been minimized.

Show comment Hide comment
@remleduff

remleduff Dec 27, 2012

From what I can see, oauth/client is expecting a map as its final optional argument. Does it work better if you rearrange it like so?

(defn upload-file
  "Upload file to Dropbox using PUT.
     root can be either `dropbox` or `sandbox`"
  [consumer access-token-response root remote-path local-path]
  (http/post (str "https://api-content.dropbox.com/1/files_put/" root "/" remote-path)
            {:query-params (make-credentials consumer
                                             access-token-response
                                             :POST
                                             "https://api-content.dropbox.com/1/files/"
                                             {:body (clojure.java.io/file local-path)}}))

From what I can see, oauth/client is expecting a map as its final optional argument. Does it work better if you rearrange it like so?

(defn upload-file
  "Upload file to Dropbox using PUT.
     root can be either `dropbox` or `sandbox`"
  [consumer access-token-response root remote-path local-path]
  (http/post (str "https://api-content.dropbox.com/1/files_put/" root "/" remote-path)
            {:query-params (make-credentials consumer
                                             access-token-response
                                             :POST
                                             "https://api-content.dropbox.com/1/files/"
                                             {:body (clojure.java.io/file local-path)}}))
@mattrepl

This comment has been minimized.

Show comment Hide comment
@mattrepl

mattrepl Dec 27, 2012

Owner

samrat: I looked at the code you linked to and it's different from what you've posted in your comment. In the linked code, you are sending in the file contents in your call to oath.client/credentials, and you shouldn't do that. Only the oauth parameters should be used to create the signature.

Please let us know which copy of the code you're using. Also, it can be useful to capture and inspect the request with your HTTP library or even Wireshark.

Owner

mattrepl commented Dec 27, 2012

samrat: I looked at the code you linked to and it's different from what you've posted in your comment. In the linked code, you are sending in the file contents in your call to oath.client/credentials, and you shouldn't do that. Only the oauth parameters should be used to create the signature.

Please let us know which copy of the code you're using. Also, it can be useful to capture and inspect the request with your HTTP library or even Wireshark.

@samrat

This comment has been minimized.

Show comment Hide comment
@samrat

samrat Dec 28, 2012

Contributor

@mattrepl - Sorry for the confusion. I'm using the version I posted here.

I was trying to send the file contents to oauth.client/credentials because there was something similar done in the README({:status "post to twitter"} was passed).

And how do I inspect the requests with clj-http? (EDIT: Ok, I found that setting :debug to true shows the request)

Contributor

samrat commented Dec 28, 2012

@mattrepl - Sorry for the confusion. I'm using the version I posted here.

I was trying to send the file contents to oauth.client/credentials because there was something similar done in the README({:status "post to twitter"} was passed).

And how do I inspect the requests with clj-http? (EDIT: Ok, I found that setting :debug to true shows the request)

@samrat

This comment has been minimized.

Show comment Hide comment
@samrat

samrat Dec 28, 2012

Contributor

@remleduff That doesn't work either.

Contributor

samrat commented Dec 28, 2012

@remleduff That doesn't work either.

@samrat

This comment has been minimized.

Show comment Hide comment
@samrat

samrat Jan 2, 2013

Contributor

Ok, I've fixed the issue- https://github.com/samrat/jopbox/blob/master/src/jopbox/client.clj#L94

Turns out that I didn't pass the full URL structure(with root and remote-path).

Contributor

samrat commented Jan 2, 2013

Ok, I've fixed the issue- https://github.com/samrat/jopbox/blob/master/src/jopbox/client.clj#L94

Turns out that I didn't pass the full URL structure(with root and remote-path).

@samrat samrat closed this Jan 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment