如何从 BlobReferenceProperty 检索 BlobStore 文件名?
我很难理解如何做一些应该简单的事情。
class Spam(db.Model):
egg = blobstore.BlobReferenceProperty(blobstore.BlobKey, required=False)
class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file')
blob_info = upload_files[0]
spam = models.Spam(egg=blob_info.key())
spam.put()
到目前为止一切顺利吧?现在我想显示该文件。
egg_blob = blobstore.BlobInfo.get(spam.egg) #error below is thrown here
self.redirect('/serve/%s' % egg_blob.key())
BadArgumentError: Expected str or BlobKey; received <google.appengine.ext.blobstore.blobstore.BlobInfo object at 0x3ed8970> (a BlobInfo)
我缺少什么? spam.egg,是一个 BlobKey。
I'm having a hard time understanding how to do something that should be straightforward.
class Spam(db.Model):
egg = blobstore.BlobReferenceProperty(blobstore.BlobKey, required=False)
class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file')
blob_info = upload_files[0]
spam = models.Spam(egg=blob_info.key())
spam.put()
So far so good right? Now I want to display the file.
egg_blob = blobstore.BlobInfo.get(spam.egg) #error below is thrown here
self.redirect('/serve/%s' % egg_blob.key())
BadArgumentError: Expected str or BlobKey; received <google.appengine.ext.blobstore.blobstore.BlobInfo object at 0x3ed8970> (a BlobInfo)
What am I missing? spam.egg, IS a BlobKey.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,我认为 Egg_blob(又名 spam.egg)是一个 BlobInfo。一旦你有了 spam.egg,我认为你不需要返回 blobstore 来获取它,是吗?您是否尝试过仅使用 spam.egg 参考?即是
No, I think egg_blob (aka spam.egg) is a BlobInfo. Once you have spam.egg I don't think you need to go back to the blobstore for it, do you? Have you tried just using the spam.egg reference? i.e. do