Question

With my webapp users can upload images as blobs in GAE. I want an easy connection between the article and the images (blobs) so I tried the following:

class Article(db.Model):
    blobs = db.ListProperty(db.Key)

and then in the blobstoreuploadhandler:

for upload in self.get_uploads():
    try:
        article.blobs.append(upload.key())

But then it gets an exception:

 /upload_form 404 3753ms 1kb Mozilla/5.0 (Windows NT 6.1; rv:28.0) Gecko/20100101 Firefox/28.0 module=default version=leakagefix
0.1.0.30 - - [20/Mar/2014:04:46:27 -0700] "POST /upload_form HTTP/1.1" 404 1331 "http://www.koolbusiness.com/ai" "Mozilla/5.0 (Windows NT 6.1; rv:28.0) Gecko/20100101 Firefox/28.0" "www.koolbusiness.com" ms=3754 cpu_ms=2036 cpm_usd=0.000149 app_engine_release=1.9.1 instance=00c61b117c8167bb98b5f7f69bd68254df45fe64
E 2014-03-20 12:46:27.190
There was an exception:Items in the blobs list must all be Key instances
E 2014-03-20 12:46:27.216
Items in the blobs list must all be Key instances

Can you tell me how it should be done and what was wrong with this attempt?

Was it helpful?

Solution

Blob keys are different from Datastore keys. Use BlobKey class:

https://developers.google.com/appengine/docs/python/blobstore/blobkeyclass?hl=ja

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top