【问题标题】:how to store the csv file into google cloud store bucket using web2py code如何使用 web2py 代码将 csv 文件存储到谷歌云存储桶中
【发布时间】:2015-06-17 06:09:58
【问题描述】:

我从 web2py 应用程序获得了 csv 文件,现在我必须通过我的 web2py 应用程序代码手动将同一个文件存储到谷歌云存储桶中(桶已经在谷歌开发者控制台中创建)

【问题讨论】:

  • 我认为您的问题与 web2py 没有太大关系。你的实现是独立于框架的。

标签: python google-cloud-storage web2py


【解决方案1】:

我不知道您如何在 web2py 中处理您的内容,但要将文件存储在存储桶中,我会这样做:

def store_file(self, filename, content):
    bucket = '/' + os.environ.get('BUCKET_NAME', app_identity.get_default_gcs_bucket_name())
    filename = bucket + '/' + filename.
    try:
        gcs_file = gcs.open(filename, 'w', content_type='text/plain')
        gcs_file.write(content)
        gcs_file.close()
    except Exception, e:
        logging.exception(e)
        try:
            gcs.delete(filename)
        except gcs.NotFoundError:
            logging.info("Could not delete file " + filename)
    logging.info("Created a file " + filename)
    return filename

我的内容变量来自 cStringIO.StringIO().getValue()

更多信息/示例here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    相关资源
    最近更新 更多