如何从BlobReferenceProperty中检索BlobStore文件名?

时间:2011-01-22 02:19:56

标签: python google-app-engine datastore 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。

1 个答案:

答案 0 :(得分:2)

不,我认为egg_blob(又名spam.egg)是一个BlobInfo。一旦你有了spam.egg,我认为你不需要回到blobstore,对吗?您是否尝试过使用spam.egg参考?即做

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