Skip to content

Instantly share code, notes, and snippets.

@noamtm
Created December 22, 2014 09:20
Show Gist options
  • Save noamtm/cadeb05bcbf693831637 to your computer and use it in GitHub Desktop.
Save noamtm/cadeb05bcbf693831637 to your computer and use it in GitHub Desktop.
Dropbox upload and share. Quick and dirty, no auth (assumes existing access token). Only tested with an app that can only access its own files, in which case the target folder is relative to the app root folder.
#!/usr/bin/env python
# usage:
# ./dropboxshare.py TARGET_FOLDER FILES ...
# Upload all files to the same folder.
# Inside the folder, files are given the same name as their origin.
# Prints a list of URLs, one on each line.
import dropbox
from sys import argv
import os
# access token from the app console (self account) or obtained from a previous auth step.
access_token = 'ACCESS_TOKEN'
target_folder = argv[1]
files = argv[2:]
client = dropbox.client.DropboxClient(access_token)
for infile in files:
basename = os.path.basename(infile)
target_file = os.path.join(target_folder, basename)
f = open(infile, 'rb')
response = client.put_file(target_file, f)
f.close()
share_info = client.share(target_file, False)
url = share_info['url']
if url.endswith('?dl=0'):
url = url[:-5]
print url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment