Skip to content

Instantly share code, notes, and snippets.

@aaronjgreenberg
Last active December 16, 2015 04:49
Show Gist options
  • Save aaronjgreenberg/5379683 to your computer and use it in GitHub Desktop.
Save aaronjgreenberg/5379683 to your computer and use it in GitHub Desktop.
Uploads a file to your Amazon S3 bucket and then copies the access URL to your clipboard.
import sys
import os.path
import subprocess
import boto
filename = sys.argv[1]
basename = os.path.basename(filename)
base_url = 'http://<bucket-name>.s3.amazonaws.com'
s3 = boto.connect_s3()
bucket = s3.get_bucket('<bucket-name>')
upload_key = bucket.new_key(basename)
upload_key.set_contents_from_filename(filename)
upload_key.set_acl('public-read')
access_url = os.path.join(base_url, upload_key.key)
pasteboard = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
pasteboard.stdin.write(access_url)
pasteboard.stdin.close()
pasteboard.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment