是否可以使用博托读取S3的文件在谷歌应用程序引擎? [英] Is is possible to read a file from S3 in Google App Engine using boto?

查看:126
本文介绍了是否可以使用博托读取S3的文件在谷歌应用程序引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想操作存储在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.

这篇关于是否可以使用博托读取S3的文件在谷歌应用程序引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆