9

I am searching everywhere and haven't been able to locate a suitable example and am not well versed enough to be able to sort it out via the docs. Could someone with more knowledge than I show me how to form the CURL command for OAUTH 2? And is it that I only need the OAUTH 2 secret key? I am being shown an App key, app secret and oauth 2. I am using this in a perl script if it matters.

The closest code I have found is this:

 curl --request PUT --header "Content-Length: `ls -la jonathan.txt | awk '{ print $5}'`" --header         
 "Content-Type: multipart/mixed" --data-binary "@jonathan.txt" "https://api-    
 content.dropbox.com/1/files_put/dropbox/jonathan.txt?access_token=ABCDEF"

But I don't think that is OAUTH 2?

3 Answers 3

15

If you have an access token (created via the app console):

curl -H "Authorization: Bearer <your token>" https://api-content.dropbox.com/1/files_put/auto/ -T <your file path>
Sign up to request clarification or add additional context in comments.

1 Comment

It looks like /1/files_put/auto is no longer available. Try /2/files/upload instead: dropbox.com/developers/documentation/http/… curl -X POST https://content.dropboxapi.com/2/files/upload --header "Authorization: Bearer <access token>" --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
9

You need an access token for the account. (This is typically acquired by going through the OAuth flow, but you can also get one for your own account by clicking the "Generate" button on the page for your Dropbox app. See https://www.dropbox.com/developers/blog/94/generate-an-access-token-for-your-own-account.)

Once you have an access token, your curl command should probably work, though I prefer --header "Authorization:Bearer abc123xyz" over putting the access token in a query parameter. Also, drop the Content-Type: multipart/mixed, since that's not what you're sending.

I'd also recommend "auto" instead of "dropbox," just because it always does the right thing regardless of the app type.

1 Comment

Thanks for that. Wish I could approve both, but since Hans made it a bit more simple by laying out the code I gave it to him. However, I do appreciate the extra info.
3

Here is working codes to upload file in dropbox via CURL request.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.