Created
April 6, 2011 19:41
-
-
Save toast38coza/906363 to your computer and use it in GitHub Desktop.
Basic wrapper round boto to create an s3 key from a string
This file contains 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
import boto | |
from boto.s3.key import Key | |
from django.conf import settings | |
#settings: | |
""" | |
AWS_ACCESS_KEY_ID | |
AWS_SECRET_ACCESS_KEY | |
DEFAULT_BUCKET | |
usage: | |
s3 = S3() | |
s3.write_string_to_s3('/path/to/file.txt','string for file') | |
""" | |
class S3: | |
def s3_connect(self): | |
return boto.connect_s3(aws_access_key_id=settings.AWS_ACCESS_KEY_ID, aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY) | |
def write_string_to_s3(self,path,string,policy='public-read'): | |
conn = self.s3_connect() | |
bucket = conn.get_bucket(settings.DEFAULT_BUCKET) | |
key = Key(bucket) | |
key.key = path | |
key.set_contents_from_string(string,policy=policy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment