我刚刚开始使用 GAE Blobstore 将图像文件上传到 Web 应用程序。我一直在使用这些资源作为教程:
http://blog.notdot.net/2010/03/Implementing-a-dropbox-service-with-the-Blobstore-API-Part-1 http://blueimp.github.com/jQuery-File-Upload/
在我下面的代码中,blob 将上传到数据存储区,我还可以检索 blob 信息。但是,经过可变延迟(可能超过 5 分钟)后,我在尝试读取 blob 信息时开始出现 EntityNotFoundErrors。blob 和 UserFile 数据仍然出现在 _ah/admin/datastore 界面中。
由于我是使用 blobstore 开发的新手,所以我想知道是否可以使用 blobstore.BlobReferenceProperty?
提前感谢您的任何建议,
布赖恩
我使用以下数据结构将用户记录链接到 blob:
class UserFile(db.Model):
user = db.StringProperty(required=True)
blob_key = blobstore.BlobReferenceProperty(required=True)
我像这样将 blob 写入数据库(通过 self.get_username 检索用户名):
def write_blob(self, data, info):
blob = files.blobstore.create(
mime_type=info['type'],
_blobinfo_uploaded_filename=info['name']
)
with files.open(blob, 'a') as f:
f.write(data)
files.finalize(blob)
# Add a userfile entry for this blob
key = files.blobstore.get_blob_key(blob)
userFile = UserFile(blob_key = key, user = self.get_username())
userFile.put()
最后,我像这样检索 blob 信息:
def get_userFileTable(self):
username = self.get_username()
userfiles = db.GqlQuery("SELECT * "
"FROM UserFile "
"WHERE user = :1",username)
for userfile in userfiles:
filename = userfile.blob_key.filename
最后一行是抛出 EntityNotFoundError 的地方
File "\scripts\filemanager\upload_handler.py", line 188, in get_userFileTable filename = userfile.blob_key.filename
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\blobstore\blobstore.py", line 179, in filename return self.__get_value('filename')
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\blobstore\blobstore.py", line 243, in __get_value
self.kind(), str(self.__key), namespace=''))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\datastore.py", line 628, in Get
return GetAsync(keys, **kwargs).get_result()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 592, in get_result
return self.__get_result_hook(self)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_rpc.py", line 1467, in __get_hook
entities = rpc.user_data(entities)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\datastore.py", line 597, in local_extra_hook
raise datastore_errors.EntityNotFoundError()
EntityNotFoundError
我在 Windows 7 机器上使用应用引擎开发服务器 1.6.5。