如何从 BlobReferenceProperty 检索 BlobStore 文件名?

发布于 2024-10-14 07:04:51 字数 742 浏览 3 评论 0原文

我很难理解如何做一些应该简单的事情。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扬花落满肩 2024-10-21 07:04:51

不,我认为 Egg_blob(又名 spam.egg)是一个 BlobInfo。一旦你有了 spam.egg,我认为你不需要返回 blobstore 来获取它,是吗?您是否尝试过仅使用 spam.egg 参考?即是

self.redirect('/serve/%s' % spam.egg.key())

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

self.redirect('/serve/%s' % spam.egg.key())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文