如何打开存储在Google Cloud Storage中的文件(从App Engine)?
我正在使用Python、Flask和App Engine (灵活的环境)。文件不是公开的,存储桶属于App Engine项目,所以设置了正确的权限。
app.yaml
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT view:app
runtime_config:
python_version: 3.5
env_variables:
CLOUD_STORAGE_BUCKET: <project-xxxx>
view.py
...
from google.cloud import storage
gcs = storage.Client()
@app.route('/start_serving/<file_name>')
def start(file_name):
WHAT TO DO HERE?
#Rest of the app
提前谢谢你。我在文档中找不到任何相关的东西。它提供了如何创建存储桶,如何上传,如何下载,如何授予权限的信息,但没有介绍如何读取。
另外,我如何在我的电脑上打开它(在运行'gcloud app deploy‘命令之前)?
发布于 2018-02-13 02:02:03
我有一个python2.7flex应用程序,在那里我使用blob.upload_from_string()
上传到GCS,但它看起来有一个blob.download_as_string()
,所以也许像这样的东西可以工作
from google.cloud import storage
project_id = os.environ['GCLOUD_PROJECT']
CLOUD_STORAGE_BUCKET = "%s.appspot.com" % project_id
@app.route('/start_serving/<file_name>')
def start(file_name):
gcs = storage.Client()
bucket = gcs.get_bucket(CLOUD_STORAGE_BUCKET)
blob = bucket.blob(file_name)
return blob.download_as_string()
https://stackoverflow.com/questions/48739671
复制相似问题