raspberry pi

Raspberry Pi Dropbox, Upload Files to Dropbox

Upload files to Dropbox:

Raspberry Pi Dropbox- Especially in connection with the Raspberry Pi camera, there is often a desire to have automatically uploaded a photo or video file to your own Dropbox account. Various Python scripts can be found on the Internet to make this task straightforward pass the Dropbox API. Unfortunately, it has been shown that such solutions do not function stably over the long term. That is why we explain the “official “, The way recommended by Dropbox.

The basic requirement is of course that you have your own Dropbox account. On the Dropbox developer pages, set up the so-called “App Console” a new Dropbox app:


For this example we have given the app the name rapi-uploader. In the Settings page of this app you will now find the Generate button to set an app-specific Generate code (a token) (see Figure1).

Amazon Purchase Links:

Raspberry Pi

raspberry pi 4 4gb kit

Wireless Keyboard and Mouse for raspberry pi:

Night vision Camera for Raspberry Pi:

Oled HDMI touch display for raspberry pi:

TOP10 Best Raspberry Pi Kits

Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

The Python functions for communicating with Dropbox are in one Extension package that is easiest to install with pip. The command name pip stands for Pip Installs Python and is its own package management system for Python. We set here to match the Python version available in Raspbian

3.2 pip-3.2

sudo apt - get install python3-pip

sudo pip -3.2 install dropbox

With the previously generated token, we can now test whether the connection is being established to Dropbox succeeds. The following mini-script should provide information about your Dropbox account:

#! / usr / bin / python3

import dropbox

dbc = dropbox. client. DropboxClient ('xxx -token -code - xxx')

print ('Account infos:', dbc.account_info ())
Raspberry Pi Dropbox
Figure 1: Set up the Dropbox app

If everything works out, it’s time for the first upload. The following lines load the File test.jpg from the local directory into the root directory of your Dropbox Accounts high:

#! / usr / bin / python3

# Dropbox - upload.py file

import dropbox

dbc = dropbox. client. DropboxClient ('xxx -token -code - xxx')

fname = 'test .jpg' # open file,

f = open (fname, 'rb')

response = dbc. put_file (fname, f) # ... upload

print ('uploaded:', respone)

close () # ... and close

Universal Dropbox authentication

We have assumed here that your script will only work with your own Dropbox account i.e it will only communicate with your Dropbox account.  The starting position is completely different when you use a script Develop to share with other users, each with their own Dropbox accounts.

In this case, you have to include code in the script that gives the user the possibility, the ability to authenticate the respective Dropbox access is directed to a Dropbox page, you have to enter your Dropbox password and then receive a special code for the script. Your script asks you to enter the code and saves it so that it can be accessed again later.

Upload photo with date and time information

The second example is a little more practical: It first creates a photo and loads it then up in the Dropbox directory. The filename of the photo under Dropbox is set composed of rapi and the date, e.g.  Rapi 2020-01-25.jpg.

#! / usr / bin / python3

# File dropbox - photo .py

import datetime, dropbox, picamera

dbc = dropbox. client. DropboxClient ('xxx -token -code - xxx')

# Create a photo and save it locally

localname = 'tmp. jpg '

camera = picamera. PiCamera ()

camera. resolution = (1280, 960)

camera. capture (localname)

camera. close ()

# Upload a photo

f = open (localname, 'rb')

today = datetime. date. today ()

upname = today. strftime ('Rapi -% Y -% m -% d. jpg')

dbc. put_file (upname, f)

close ()


Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button