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

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。

最佳答案

不,我认为egg_blob(aka spam.egg)是BlobInfo。有了spam.egg之后,我认为您无需再回到Blobstore了,是吗?您是否尝试过仅使用spam.egg参考?即做

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

关于python - 如何从BlobReferenceProperty检索BlobStore文件名?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4765751/

10-10 23:58