How to retrieve BlobStore file name from BlobReferenceProperty?
-
16-10-2019 - |
Question
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.
Solution
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())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow