Skip to content Skip to sidebar Skip to footer

Is Is Possible To Read A File From S3 In Google App Engine Using Boto?

I want to manipulate a pickled python object stored in S3 in Google App Engine's sandbox. I use the suggestion in boto's documentation: from boto.s3.connection import S3Connection

Solution 1:

You don't need to write to a file or a StringIO at all. You can call key.get_contents_as_string() to return the key's contents as a string. The docs for key are here.

Solution 2:

You can write into a blob and use the StringIO to retrieve the data

from boto.s3.connectionimport S3Connection
from boto.s3.keyimportKeyfrom google.appengine.extimport db

classData(db.Model)
    image = db.BlobProperty(default=None)

conn = S3Connection(config.key, config.secret_key)
bucket = conn.get_bucket('bucketname')
key = bucket.get_key("picture.jpg")
fp = StringIO.StringIO()
key.get_file(fp)

data = Data(key_name="picture.jpg")
data.image = db.Blob(fp.getvalue())
data.put()

Post a Comment for "Is Is Possible To Read A File From S3 In Google App Engine Using Boto?"