cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Upload/Download files via shell (Android-Linux)

Upload/Download files via shell (Android-Linux)

SmartPhoneLover
Explorer | Level 3

Hi all,

I'm looking for upload and download files from an Application folder I have created on my account (with token). -> e.g. = Applications > app_name > Private > file.xxx

 

The code I will use on shell will be:

curl -X POST https://content.dropboxapi.com/2/files/upload \
    --header "Authorization: Bearer ACCESS_TOKEN" \
    --header "Dropbox-API-Arg: {\"path\": \"/Private/file.xxx\"}" \
    --header "Content-Type: application/octet-stream"

 

Quesitons:

· Is the above code correct? Does it requiere more things to be added/modified?

· What should I add to the code to pick a specific file from x location to be uploaded? (e.g. = want to upload temp.txt file from /sdcard/Download/folder1/*)

· How may have this code to be modified to allow getting back that file, from my Dropxbox account, to my device again. (download file) [I think that replacing '...2/files/upload' by '.../download' will be enought]

 

Thanks.

4 Replies 4

Re: Upload/Download files via shell (Android-Linux)

Greg-DB
Dropboxer

Your code seems to be missing the part where you supply the file data for upload. You can find a sample of what the upload API call should look like in the documentation here:

 

https://www.dropbox.com/developers/documentation/http/documentation#files-upload

 

Likewise, the download call has documentation and a sample here:

 

https://www.dropbox.com/developers/documentation/http/documentation#files-download

 

The API v2 Explorer can be useful for building these calls, e.g., for upload and download.

Re: Upload/Download files via shell (Android-Linux)

SmartPhoneLover
Explorer | Level 3

Thank you. Yes, I forgot to add '--data-binay @...' at the end. Now works pefect!

Thanks!

Re: Upload/Download files via shell (Android-Linux)

SmartPhoneLover
Explorer | Level 3
I tried:
cd /sdcard/Download ; curl -X -O POST https://content.dropboxapi.com/2/files/download \
--header "Authorization: Bearer TOKEN_ID" \
--header "Dropbox-API-Arg: {\"path\": \"/Private/fmc_database.db\"}"

...but Terminal tell me that Dropbox does not support the '-O' argument. So, what I need to add to the cmd to allow saving the file to my local storage's device?

Re: Upload/Download files via shell (Android-Linux)

Greg-DB
Dropboxer

The "-X" flag takes a parameter for the HTTP method to use, which should be "POST". In your code though, you've put the flag "-O" directly after that, so curl will send that as the method, which isn't valid. You would just need to move that out of that spot, e.g.,:

 

curl -O -X POST https://content.dropboxapi.com/2/files/download \
--header "Authorization: Bearer TOKEN_ID" \
--header "Dropbox-API-Arg: {\"path\": \"/Private/fmc_database.db\"}"

 

That "-O" option isn't really well suited for the Dropbox API though anyway, per the curl documentation:

 

       -O, --remote-name
              Write output to a local file named like the remote file we get. (Only the file part of the remote file is used, the path is cut off.)

              The remote file name to use for saving is extracted from the given URL, nothing else.

That would just take the name from the URL, which would just be "download". The Dropbox API instead returns the file's metadata as JSON in the "dropbox-api-result" result header. You should parse it out from there instead if you want the actual file name.

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    SmartPhoneLover Explorer | Level 3
What do Dropbox user levels mean?
Need more support?