【问题标题】:In Google App Engine, how do you use a blobstore key to read from the blob line-by-line?在 Google App Engine 中,如何使用 blobstore 键逐行读取 blob?
【发布时间】:2012-02-02 01:56:52
【问题描述】:

我正在使用 blobstore 在 Python 版 Google App Engine 中上传和下载文件。我了解如何将对象逐行写入 blobstore,并且我了解如何发布和下载 blobstore 项目,但是如果我只有 blobstore 键,我如何逐行从 blobstore 中读取数据?

file_name = files.blobstore.create(mime_type='application/octet-stream')

with files.open(file_name, 'a') as f:
    f.write("data")

files.finalize(file_name)
# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)

#starting with the blob_key, read from the blobstore line-by-line.
# ???
#with files.open() as f:
#foo = f.read()

【问题讨论】:

    标签: google-app-engine blobstore


    【解决方案1】:

    我认为您需要blob reader。下面是一个使用示例:

    from google.appengine.ext import blobstore
    
    blob_reader = blobstore.BlobReader(blob_key)
    for line in blob_reader:
        process_line(line)
    

    【讨论】:

      猜你喜欢
      • 2012-05-02
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      • 2016-11-26
      • 1970-01-01
      • 2013-12-25
      • 2013-09-23
      • 2011-01-14
      相关资源
      最近更新 更多