在Google App Engine中,如何使用blobstore键逐行读取blob?

时间:2012-02-02 01:56:53

标签: google-app-engine blobstore

我正在使用blobstore上传和下载python版本的Google App Engine中的文件。我理解如何逐行将对象写入blobstore,我了解如何POST和下载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()

1 个答案:

答案 0 :(得分:3)

我认为你需要blob reader。以下是使用示例:

from google.appengine.ext import blobstore

blob_reader = blobstore.BlobReader(blob_key)
for line in blob_reader:
    process_line(line)
相关问题