2012-02-02 50 views
0

我正在使用blobstore上傳和下載python版Google App Engine中的文件。我知道如何逐行編寫對象到blobstore,並且我知道如何POST和下載blobstore項目,但是如果我擁有的是blobstore項目,那麼如何逐行讀取blobstore中的數據?在Google App Engine中,您如何使用blobstore鍵逐行讀取blob?

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() 

回答

3

我認爲你需要blob reader。以下是使用示例:

from google.appengine.ext import blobstore 

blob_reader = blobstore.BlobReader(blob_key) 
for line in blob_reader: 
    process_line(line) 
相關問題