我想操作存储在S3在谷歌App Engine的沙箱中的腌Python对象。我用的是建议在博托的文档:
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
from boto.s3.key import Key
conn = S3Connection(config.key, config.secret_key)
bucket = conn.get_bucket('bucketname')
key = bucket.get_key("picture.jpg")
fp = open ("picture.jpg", "w")
key.get_file (fp)
不过这需要我写一个文件,这显然是不洁净的GAE沙箱。
but this requires me to write to a file, which apparently is not kosher in the GAE sandbox.
我怎样才能解决这个? 感谢很多的帮助。
How can I get around this? Thanks much for any help
您不必写入一个文件或StringIO的都没有。您可以拨打 key.get_contents_as_string()
返回键的内容作为一个字符串。该文档的关键是这里。
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.