[当我使用mongodb的python api mongoengine从GridFS读取文件时,第一次读取后得到的内容为空。这是我尝试过的:
class Test(Document):
file=FileField()
a = Test(id=id)
print a.file.read() # has expected output
print a.file.read() # empty
print a.file.read() # empty`
所以,我对GridFS的读取方式感到好奇,在此先感谢您提供任何提示:)
[我们必须改进相应的documentation作为常见的错误来源,但一旦阅读流,就需要“倒带”该流。
即:
class Test(Document):
file = FileField()
a = Test(id=id)
print a.file.read() # has expected output
a.file.seek(0)
print a.file.read()