Aug 052013
 
Dropbox-pi

I wanted to be able to upload photos from my RasPiCamcorder straight to DropBox. So I did a little research and came across an absolute gem of a program called Dropbox-Uploader, by Andrea Fabrizi.

A truly brilliant piece of work that gives you access to your DropBox account right from the command line.

You do have to jump through a couple of hoops to get it set up (security mostly), but once you’ve done that, it’s a breeze.

1. DropBox account

First of all you need a DropBox account. Hop on over to DropBox and get one – it’s free.

2. Download and Set Up DropBox Uploader

Next, you need to get Dropbox Uploader onto your Pi

cd ~ this ensures you are in /home/pi
git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
ls

(If this fails, you may need to install git with sudo apt-get install git-core)

You should be able to see a directory called Dropbox-Uploader

cd Dropbox-Uploader
ls

You should now see three files, one of which is called dropbox_uploader.sh. This is the script we’re going to use.

DropBox-Uploader files

3. Now the fiddly bit – API keys

Run the script with ./dropbox_uploader.sh (if it fails, try chmod +x dropbox_uploader.sh)

You should see this…

Sorting out the DropBox API keys

You then need to visit this link https://www.dropbox.com/developers/apps, login to DropBox and create an “app” by clicking the “create app” button.

Then choose “Dropbox API app”, “Files and Datastores”, and answer the final question “Can your app be limited to its own, private folder?” – either answer is OK, depending on your needs.

Then you need to give your app a unique name, and you will be assigned some keys to go with the name. Now you need to type in those keys here…

Entering your app’s DropBox API keys

Once you’ve entered your keys and answered the question “app” or “full”, your Pi will request an authorisation token and you will be given a web URL you need to visit to activate it…

DropBox API authorisation

This is the part which annoyed me, as I was using a different computer to ssh into the Pi and couldn’t cut and paste the “rather tricky to type accurately” URL. But once you’ve got past that hurdle it should all just work. :)

If it works, you should see this in your browser…

Your DropBox account connected to your “app”

4. Now you can use DropBox Uploader on your Raspberry Pi…

…from the command line like this…

cd home/pi/Dropbox-Uploader
./dropbox_uploader.sh upload /home/pi/name_of_upload_file name_of_upload_file

This will upload the file you choose to your DropBox account.

…or use it in a Python script like this…

from subprocess import call
photofile = "/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload /home/pi/photo00001.jpg photo00001.jpg" 
call ([photofile], shell=True)

And, if you look at the DropBox Uploader documentation, there’s a lot more commands you can make use of…

  • upload
  • download
  • delete
  • move
  • list
  • share
  • mkdir

I think this is brilliant. Yes you have to jump through a couple of hoops, but to be able to take a photo and see it on my PC, phone or Nexus 7 tablet within 30 seconds is pretty darned cool. I’ll jump through a couple of hoops for something that cool.

Here’s what it looks like in action, taking a photo and uploading to DropBox automatically. The DropBox upload photo part starts at 5m 7s.

  105 Responses to “How to use DropBox with Raspberry Pi”

  1. Now _that_ is a handy piece of software :-)

    • It’s brilliant isn’t it? What I love about it is that it’s basically a bash script using curl, so nothing much to install. You can call it from a Python script, and once you’ve done the initial setup it “just works”. :)

  2. You forgot to mention an easy way to manage/navigate dropbox with nice addon dropShell

    • LOL. I didn’t forget anything, I didn’t even know about it :p

      But I will delve into that further when I get the chance – it sounds interesting. Thanks for the tip. :)

  3. Hi Alex
    I got through the procedure, and got the message –

    Success! KCuploader2 is connected to your Dropbox.

    However, when I tried to upload a file called colours.jpg, it failed:

    pi@raspberrypi ~/Dropbox-Uploader $ ./dropbox_uploader.sh upload /home/pi/colours.jpg
    > Uploading “/home/pi/colours.jpg” to “/colours.jpg”… FAILED
    An error occurred requesting /upload
    pi@raspberrypi ~/Dropbox-Uploader $

    Can you see what I’m doing wrong?

    Cheers
    Kieran

    • Not unless it’s something silly like colours.jpg being in a directory other than /home/pi or internet connectivity?

      Try a different command? e.g. list.

      I haven’t played with this at all, but it would tell you if there was a general connectivity issue or a problem with the file you tried to upload.

    • Same problem. Did you resolve it?

      • Steve says: I am a mech eng and noooo expert but I just managed to load up dropbox and add files. Some points are: 1) Case sensitive; 2) I don’t think it will like the “/”. I used the command $ ./dropbox_uploader.sh /home/pi/Photos/IMG0052.JPG IMG_0052.JPG to test the ADAFRUIT PiCam BUT 3) I had to make a directory in Dropbox for Photos first. This is why I don’t think it likes the “/”. Cheers Steve

    • Same problem here, too. Will try again with it at some point, though, as this could be really useful.

    • Did you guys give dropboax uploader access to your whole dropbox or just a specific directory? I gave it access to the whole lot. Just wondering if it makes a difference?

      • Worked perfectly second time around. Looks like I did list the wrong access level when setting up the Pi. I had to delete the Dropbox app, and unlink the Pi (./dropbox_uploader.sh unlink) before I could redo the Pi setup. Thanks for a really useful tutorial.

        • So which access level was the wrong one? And which was the right one? I’ve never tried anything other than full access.

          • I think first time around I told Dropbox to give the app access to the app folder only, and then mistakenly told Dropbox Uploader that it had full access. I’ve now got it working with full access, but I’ve no reason to think that folder access wouldn’t work.

          • Excellent – thanks :)

  4. This looks great to use just done the Dropbox app and installed the keys
    can you advise as I have never had the pi on the web direct what browser would you recommend. I do not use any desktop programs with it.

    Terry

    • I did the web browser bit with my laptop (hence the comment about having to retype the tricky URL). But you can use Midori as a browser if you’re patient. (It’s not the Pi’s strength – frankly it’s too darned slow for me, but web browsing is not what it’s for IMHO – I have plenty of other devices that do that well.)

      • Thanks for quick reply despite being a very old noob well I cut my teeth on Nascom and ZX81. I had saved the web link but it has timed out so start again tomorrow.
        It is easy to copy paste from PI using Putty to a Vistal Laptop.
        It took me a time to find just highlight the pi text with left mouse click and hold drag to end of the text. Do nothing more in Putty
        Open the text edit program and do a ctrl v and the pi text is pasted to your program or browser address bar

        Terry

        • Hi Terry,
          Join the club….ZX81 was my first intro to programming…1kb or a 16kb wobbly RAM pack! Is it me or was Z80 machine code a damn site easier than Linux???

          Anyway, just to add to your comments about copy/paste….
          Alex, as I assume you are copying the other way (ie copy from PC and paste to RPi) you select the text from your browser (or wherever) and CTRL C as usual then use PUTTY and just right-click. The text is pasted straight away. The other way, highlighting PUTTY text automatically copies it to the clipboard.

          Dave

  5. Hi Alex,
    Brilliant!!
    Your instructions are great! Unlike most things I’ve tried to do with the Pi, I went from reading your post to uploading a file to dropbox in about 5 minutes!!!

    Thanks again……now we just need a GUI method! ;-)

    Dave

    • Thank you Dave. That would be mission accomplished then. Clear, precise instructions that work first time is what I strive for. I don’t do GUI on pi (yet).

  6. All worked first time today thanks a lot for you time and effort.
    PI to DropBox to Laptop takes 11 seconds .

  7. Cool. Works. Give it a try :) Thank You

  8. I tried it and it works perfectly. Thanks.

    I just have one question. By any chance, does anybody know a simple way to get (and use) the information given by the instruction “list” inside my python script ?

    I would like for exemple that my python script compare the content of a dropbox (remote) folder with a local folder. I have tried to google this issue but I did not find anything I could really use.

    I have to confess that I am still a newbie with both python and RPI (but oh boy, I have so much fun ;) )

  9. Thanks, great article

  10. I have been using Dropbox with my Rpi from the beginning, but via my linux workstation and the “sshfs” command.

    On the Rpi, I use “sshfs :Dropbox Dropbox”

    Then I use the Rpi Dropbox directory as normal.

    Works like a champ.

  11. Oh, oh!

    git clone https://github.com/andreafabrizi/Dropbox-Uploader.git

    returned:
    Cloning into ‘Dropbox-Uploader’…
    error: The requested URL returned error: 503 while accessing https:/github.com/
    andreafabrizi/Dropbox-Uploader.git/info/refs
    fatal: HTTP request failed

    pi@raspberrypi ~ $

    Problems in Andea’s directory?

    Help please.

  12. I got it working! Going to Andrea’s site took me through it. The above git clone command evidently didn’t like the …-Uploader.git at the end, wanted …-Uploader/ (no .git)

    Here is the link to her site: – good luck everybody – cool stuff!

    https://github.com/andreafabrizi/Dropbox-Uploader

  13. I seem to have linked it to the wrong a/f. Unlink didn’t seem to work for me. What’s the easiest way to uninstall the Dropbox-Uploader and start a fresh?

    Thank you, and very helpful. I had this working on another SD and it works seamlessly!

    • It’s just a bash script, so not really “installed” as such. I don’t know quite what it does with the keys and token though. The only foolproof way would be to flash a fresh SD card, but it’s probably really only a question of finding and deleting a couple of files.

      • Okay, no worries. I think it’ll be as quick to do a fresh SD ;)

        • All working. It was down to me using ‘f’ instead of ‘a’. Fresh SD did the job. I’m sure theres a quicker way, but for me it was quicker to just do a fresh install. This is part of an art exhibition in london at some point in spring next year. I’ll send some pics over to see your script on a big scale ;)

          Great work.

  14. Could I ask where the default configuration file is? I don’t see one in the location stored in the code – I have the default installation.
    Thanks for a great product,
    TIm

    • I think you’d be best off contacting the author through his GitHub account :)

    • If I understand correctly what you’re looking for the file is .dropbox_uploader (with a dot at the front) in your home directory.
      Type ls -al for a listing including any config files.
      It contains details of your APPKEY, APPSECRET, ACCESS_LEVEL, OAUTH_ACCESS_TOKEN and OAUTH_ACCESS_TOKEN_SECRET.

      • Thanks Neil – I eventually emailed the author and he kindly put me on the right track. I use DU with a couple of piCams to look at the view from my windows when traveling – very nice. It’s also good for tracking your home IP remotely without use a DDNS – very handy.

  15. Hi, Thanks for the tutorial the upload to dropbox works only manually “./dropbox_uploader.sh upload /home/pi/ocr_pi.png”
    but if i run it with the attached Python script it shows some error on line 4

    Please help ..

    Thanks.
    Nick.

  16. Hi, great tutorial.
    is there a script that takes the last created file and uploads it to Dropbox?
    not sure if i have missed something as your video does it but i can’t see any code to do this.

    this is what i have so far: –

    from subprocess import call
    import os
    import glob
    newest = max(glob.iglob(‘*.jpg’), key=os.path.getctime)

    photofile = “/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload /home/pi/ newest”
    call ([photofile], shell=True)

    so as you can see i have just replaced the file name with the ‘newest’ object but it just sees it as a file name.

    Thanks,

  17. To upload any file from command line try:
    write python app:

    from subprocess import call
    import sys
    TheCall = “/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload ” + sys.argv[1] + ” /DropboxDestination”
    call ([TheCall], shell=True)

    The, from the command line do something like: python dropbox.py /home/pi/test.txt

  18. I can’t get the Uploader to work. I got through the tutorial OK, but could not see the .jpg on the Dropbox. I used:
    ./dropbox_uploader.sh upload /home/pi/name_of_upload_file with my .jpg file name. All I get is Uploader help file.
    I decided to re-install the Dropbox-Uploader again, removing the old directory. I can do the git command to download the file OK. But, now I can’t run even run this script:
    ./dropbox_uploader.sh I just get the help file again.

    • I found the trouble. If I use the Andrea script without the .git at the end, replaced by a forward slash, it works.

  19. Uploader wont work. Reinstalled Dropbox-uploader and getting help file. removed .git from:
    git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
    to get: git clone https://github.com/andreafabrizi/Dropbox-Uploader/ and it still goes into help menu
    Any ideas?

    • I’ve just had a look at this myself – looks like the syntax of the script has changed slightly (maybe Alex could add a note to the article above) and the ‘upload’ option now requires a destination filename in Dropbox. I.e. instead of:
      ./dropbox_uploader.sh upload /home/pi/myfile.jpg
      you now need to do:
      ./dropbox_uploader.sh upload /home/pi/myfile.jpg myfile.jpg

      • Thanks for that. Will make changes in the text. I’m still using the old version on my RasPiCamcorder.

        • I following the steps as above, but when I run Run the script with ./dropbox_uploader.sh (if it fails, try chmod +x dropbox_uploader.sh) for the first time, I do not get the option of adding my app, I just get the help menu.

          Why is that?

          Dave

          • Maybe dropbox_uploader.sh is already linked to your account? Try
            rm ~/.dropbox_uploader
            and then try again?

      • I tried the code a couple different ways (please forgive me if I have reposted this) I have a couple questions. one: are you suppose to have a app folder inside the dropbox folder and suppose to direct the files to go into that folder? I change the destination folder to three subfolders in the same folder that the .sh is in. (i.g. /home/pi/subfolder1/subfolder2/subfolder3/tada.jpg) but when I run the code it “no such directory or file found /home/pi/……. I have a couple prematations of the order of the directories and beginning slashes and no slashes…so far it all ends with depression and failure.

        • Have you done ‘mkdir -p /home/pi/subfolder1/subfolder2/subfolder3′ ? Linux doesn’t auto-create “missing” folders for you.
          (If it’s not that, I don’t have any other suggestions as I don’t use this Dropbox script)

          • I figured it out what was happening. I had misspelled the the first folder so it was giving me an error. If anyone can tell me how to: make this run on boot and repeat it and run a script that cleans the folders. I have the clean script and I know how to get this one to run. I just need something to the them together and make it run constantly.

          • Make it run at boot: edit rc.local
            Make it repeat: edit crontab

            Searching google (or the Raspberry Pi forums) will give you *lots* more info about either of them :)

  20. Yup, that worked, thank you.

  21. Hi all. Brilliant solution. Thanks for the excellent guides, Alex.

    I’ve a but I can’t crack. Dropbox-uploader works great when I call it from command line, but when I try to do so within a script, I am prompted to enter the app key as if I’ve not linked the app. For some reason if I initiate the shell script while not in the Dropbox-Uploader folder, I get the same result: requesting the app key. Even tried an os.chdir in the script to get around this, thusly:

    #!/usr/bin/env python
    #picamera_test.py

    import time
    import picamera
    from subprocess import call
    import os
    import glob

    newest = max(glob.iglob(‘*.jpg’), key=os.path.getctime)

    camera = picamera.PiCamera()
    try:
    camera.start_preview()
    time.sleep(2)
    camera.capture(‘test.jpg’)
    camera.stop_preview()
    os.chdir(“/home/pi/Dropbox-Uploader”)
    photofile = “./dropbox_uploader.sh upload /home/pi/” + newest + “Code/Pi” #tried with and without specifying filename to place
    call([photofile], shell=True)
    finally:
    camera.close()

    Any help is greatly appreciated.

  22. I have a problem with the starting upload a file at boot. Could anyone help me?

  23. Hy Mr, i have problem
    while i write scrip… git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
    but show // error: server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none while accessing https://github.com/andreafabrizi/Dropbox-Uploader.git/info/refs
    fatal: HTTP request failed
    i hope help you,,, thank you

  24. hello, thx for a good tutorial
    but is there a way to download whole dropbox at once win this script?

  25. Thanks for the tutorial,
    I have one small problem, every time a photo uploads to dropbox it overwrites the last photo that was sent. Any ideas on how to fix this?

    Thanks

    • Are you using the same file name for each photo? If you use a unique name for each shot, surely that won’t happen?

      • That is probably the problem, How can I change that? I am really new to working with the RasPi.

        • Without saying how you’re taking the photo, I can’t really help. If you’re using raspistill, the bit after the ‘-o’ defines the file name

          e.g. raspistill -t 500 -o /home/pi/photo.jpg

          photo.jpg should be different for each photo

  26. The pictures appear to get a unique file name when saved in the Pi folder (consecutive numbering) but after the uploader moves the file to dropbox the file name is changed to Photo. makes me think something needs to be modified in the uploader..

  27. Thanks, Alex, to your excellent tutorial, my Raspi located very far away is sending me every night on my dropbox the pics of the day. It has been working for 6 months now….GREAT.
    But the internet connection at the place where the raspi is, is not reliable and the signal drop down from time to time…I am thinking to add to your python script:
    01.from subprocess import call
    02.photofile = “/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload /home/pi/photo00001.jpg photo00001.jpg”
    03.call ([photofile], shell=True)

    some sort of loop or while true

    but I don’t know really the exact syntax to apply
    Have you an idea ?

    Michel

  28. i would like to use this to up date files at multiple sites updates would be as needed upload for home and download to sites maybe once a week. Would be willing to listen to any advice please and thank you.

  29. Photos are in Photos Folder.
    /home/pi/Photos

  30. I am trying to get this to work. I have gotten it Connected (I think) but there is no app folder that pops up. Shouldn’t there be like a folder in Dropbox if things done right. I changed the syntax so I don’t get the menu but I getting a “no such file or directory exist” error. But it does… Help.

  31. I got the token error when upload my appkey & appsec.
    it told no such folder or dictionary .
    anyone who can help me with it、
    Thanks in advance!

    • Umm, what? You don’t need to ‘upload’ your appkey and secret.
      Try following the instructions again, but more carefully?

  32. im trying to upload a photo(that captured with pressing a buttun on raspberry input)to dropbox.can i use this app to my project?

  33. Hi Andrea, thanks for the great tutorial. Managed to install everything but I believe I haven’t quite understood one thing: I am using my RPi as a digital picture frame and would like to have one dropbox folder (with many subfolders) to which my family can upload pictures (in folders and directly) by using the dropbox link. Is that possible with this setup?

    • Looking at the instructions for the DropboxUploader script at https://github.com/andreafabrizi/Dropbox-Uploader I guess you’ll need to use the download option of dropbox_uploader.sh (assuming I’ve understood your question correctly) – it says it supports “File and recursive directory download”.
      You’ll probably want a bash script running in an infinite loop, which recursively downloads your selected directory, waits 15 minutes, tries recursively downloading your directory again (to see if any new photos have been added), waits another 15 minutes, etc.

      P.S. Andrea is the author of DropboxUploader, but the tutorial on this page was written by Alex :-)

      • Thanks Andrew. I get to step 4 without problems, but I have no idea how to write the script where I get one particular folder with the respective subfolders to be synched every five minutes. I guess I can put repeated execution into the crontab but how would the script have to look like? Sorry, for maybe asking very basic questions..

        • Yeah, using crontab is probably an easier / more reliable option than writing a script to run in an infinite loop. Although IMHO “every five minutes” is perhaps a little too frequent – if you have a lot of photos to download, you might end up with two instances of the download script running at once?!
          You should just be able to put something like “/home/pi/Dropbox-Uploader/dropbox_uploader.sh download photos/shared /home/pi/dropbox-photos” into your crontab, although you’ll obviously have to experiment with what paths the script needs, and google has plenty of info on editing crontabs.

          • For some reason, every a manual upload of a file doesn’t land in my dropbox. I tried ./dropbox-uploader.sh upload /home/pi/ocr_pi.png but the file never shows up in my dropbox. How do I specify where it should show up in dropbox?

            Regarding crontab, yes once very couple of hours would be enough anyone.

          • Try re-reading the documentation…
            https://github.com/andreafabrizi/Dropbox-Uploader

          • Well, I managed to get a file to dropbox with
            ./dropbox_uploader.sh upload /home/pi/frame/photos/*.* /mydropboxdirectory
            but this only does upload, the other command only download or delete. What to I have to specify to rsync a dropbox directory with a directory on the Raspberry? Also it didn’t upload the folders in the directory only the photos in that directory..

          • Baby step success! The recursive upload works when I just write ./dropbox_uploader.sh upload /home/pi/frame/photos /mydropboxdirectory

          • So how I sync? :-))

          • I’ve got no idea, that’s why I said you’ll need to read the documentation and experiment with different paths…

          • Hmm, I find it hard to believe that I am the first one who wants to sync a directory, not just up- and download something… :-(( Andrea’s script is so great and he surely must have thought of that…

          • Ahhhh, I think I see what you’re saying now…
            There’s no way for Andrea’s script to offer “sync” functionality, because if (either by accident or deliberately) the same file exists both in Dropbox *and* on the Pi, then Andrea’s script has no way of knowing which is the correct version! That’s why it’s “upload only” or “download only” – it’s up to you to make sure the files are being copied in the right direction ;)
            To do proper two-way sync you’d need to use the official Dropbox client, and unfortunately that’s not available for ARM Linux… (the Pi uses an ARM CPU).
            Sounds to me like your best option might be to have one subfolder for copying from the Pi up to Dropbox, and a different subfolder from copying from Dropbox down to the Pi? (and you’d need a separate cronjob for each)

          • P.S. Have a look at some of the closed feature requests…
            https://github.com/andreafabrizi/Dropbox-Uploader/issues?q=is%3Aissue+sync

  34. Hi,

    Forgive me if it seems stupid but I’m new to the Pi.

    This is a great piece of code and I got it to work (third time after typing carefully). Has anybody tried the “Move” command? What I’m trying to do is to take some time elapse photography and I don’t want the pictures stored on the SD card. I assumed that move was the same as upload except that it would delete the file after it had been uploaded. However, although I can upload successfully, move comes back “FAILED”.

    I suppose the alternative would be to upload the file and then remove it from the Pi but I’m not sure either how to do that in Python nor how to make sure that the file has been uploaded before it gets deleted.

  35. Fantastic – up and running in 15 minutes, thank you so much.

Leave a Reply