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.

  76 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

  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

  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.

  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

  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

  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