Python‎ > ‎

Python code to upload images to DropBox

posted Sep 5, 2014, 12:15 AM by Chris G
Using the DropBox Python package is a fairly straightforward task. You will first need to obtain a DropBox API access token for your application.

The following code will upload all .jpg files from your local system to your DropBox application (and delete the local files IF YOU REALLY WANT TO).
import dropbox
from glob import iglob

access_token = '<your access token>'
client = dropbox.client.DropboxClient(access_token)
print 'linked account: ', client.account_info()
PATH = ''

for filename in iglob(os.path.join(PATH, '*.jpg')):
	print filename
	try:
		f = open(filename, 'rb')
		response = client.put_file('/' + filename, f)
		print "uploaded:", response
		f.close()
		#os.remove(filename)
	except Exception, e:
		print 'Error %s' % e


Comments