【问题标题】:Download Files from GCS: Google App Engine从 GCS 下载文件:Google App Engine
【发布时间】:2013-11-22 12:28:13
【问题描述】:

我是 GCS 的新手。并尝试从 GCS 读取和下载文件。

这里我写了几行。

from google.appengine.api import files

def download_data_from_gcs(request):
    file_name = '/gs/bucket-name-1/new_file.csv' # change bucket/object names to suit your needs
    with files.open(file_name, 'r') as f:
        data = f.read()
        logging.error(data) # I'm getting here csv data. Its around of ~20-25 MB

现在棘手的部分是按原样下载这个dataEx. new_file.csv

有人解决了吗?会很感激的。

谢谢

【问题讨论】:

  • 你想把它下载到哪里?到 App Engine 应用,在代码中使用,还是到最终客户端?
  • @DanielRoseman:如果能在客户端下载就好了。

标签: python google-app-engine google-cloud-storage


【解决方案1】:

不能直接从网址下载吗?

https://storage.cloud.google.com/bucket-name-1/new_file.csv

如果需要 Google 登录,则它使用文件所在存储桶中的默认 ACL。

当您将文件写入 gcs 时,您可以在选项字典中将文件的 ACL(权限)设置为 public:

gcs_file = cloudstorage.open(filename, 'w', content_type='text/plain', options={'x-goog-acl': 'public-read'})

【讨论】:

  • 这不是可以通过程序吗?
  • 写文件代码参考:Moving to GCS
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-11
  • 2018-01-12
  • 2020-01-08
相关资源
最近更新 更多