Created
April 17, 2011 14:01
-
-
Save comfuture/924047 to your computer and use it in GitHub Desktop.
put a file or url to amazon s3 service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import mimetypes | |
import urllib | |
import os.path | |
import sys | |
import S3 # grep http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134&categoryID=47 | |
AWS_ACCESS_KEY_ID = '****' | |
AWS_SECRET_ACCESS_KEY = '****' | |
BUCKET_NAME = '****' | |
def put_url(url): | |
conn = S3.AWSAuthConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) | |
dummy, _slash, filename = url.rpartition('/') | |
content_type = mimetypes.guess_type(filename)[0] | |
if not content_type: | |
content_type = 'application/octet-stream' | |
print 'uploading... [%s]' % url | |
conn.put(BUCKET_NAME, 'public/' + filename, S3.S3Object(urllib.urlopen(url).read()), | |
{'x-amz-acl': 'public-read', 'Content-Type': content_type}) | |
print 'Done: http://%s/public/%s' % (BUCKET_NAME, filename) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print 'Usage: %s [filename or url]' % sys.argv[0] | |
put_url(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment