thumbnail is an instance of images.Image() and is okay - I am able to save it to ndb datastore and serve it as described here: Displaying Blob Images in Python (App Engine)
Everything seems to work ok but I am unable to navigate to the generated URL on my dev server (am unable to try it on gae at this point). What I do is as follows:
blobstore_file = files.blobstore.create(mime_type='image/jpg')
with files.open(blobstore_file, 'a') as f:
f.write(thumbnail)
files.finalize(blobstore_file)
url = images.get_serving_url(blobstore_file)
When I go to Blobstore Viewer I am able to see the picture just fine. However, the generated URL
http://localhost:8080/_ah/img//blobstore/writable:VjNUUUVINDZEOE9BQTlSMTNKSVFIMEJQN1RMWUIyUjFNUTROQjlZVjlKQlBSME1aR1c4M1NKRENRUVA3UktDSA==
returns 400 Bad Request and this is the ERROR that is thrown in the logs:
ERROR 2014-04-24 12:36:58,508 blob_image.py:168] Failed to parse image path "/_ah/img//blobstore/writable:VkFEMDVQMjNSNVQyT1NGTDFWQjMxRDU4SzhKM1hJOEMzNk5DQzgxOTlEWUtKRUhMQlQ0WTlGMFpCNFlXQU9DVA=="
Any help would be greatly appreciated as googling this didn't turn anything up. Thank you,
Edit: After making the changes as radia suggested I now get an error msg as below:
WARNING 2014-04-24 13:57:37,025 tasklets.py:409] suspended generator transaction(context.py:941) raised AttributeError('Key' object has no attribute 'reference')
ERROR 2014-04-24 13:57:37,025 webapp2.py:1553] 'Key' object has no attribute 'reference'
Traceback (most recent call last):
File "/home/radek/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 1536, in __call__
rv = self.handle_exception(request, response, e)
File "/home/radek/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 1530, in __call__
rv = self.router.dispatch(request, response)
File "/home/radek/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/radek/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/home/radek/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/home/radek/google_appengine/lib/webapp2-2.5.1/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/home/radek/google_appengine/google/appengine/ext/deferred/deferred.py", line 309, in post
self.run_from_request()
File "/home/radek/google_appengine/google/appengine/ext/deferred/deferred.py", line 304, in run_from_request
run(self.request.body)
File "/home/radek/google_appengine/google/appengine/ext/deferred/deferred.py", line 146, in run
return func(*args, **kwds)
File "/home/radek/google_appengine/google/appengine/ext/ndb/utils.py", line 179, in inner_wrapper
return wrapped_decorator(func, args, kwds, **options)
File "/home/radek/google_appengine/google/appengine/ext/ndb/model.py", line 3718, in transactional
func, args, kwds, **options).get_result()
File "/home/radek/google_appengine/google/appengine/ext/ndb/tasklets.py", line 325, in get_result
self.check_success()
File "/home/radek/google_appengine/google/appengine/ext/ndb/tasklets.py", line 371, in _help_tasklet_along
value = gen.send(val)
File "/home/radek/google_appengine/google/appengine/ext/ndb/context.py", line 937, in transaction
result = callback()
File "/home/radek/google_appengine/google/appengine/ext/ndb/model.py", line 3726, in <lambda>
return transaction_async(lambda: func(*args, **kwds), **options)
File "/home/radek/prasowalnia/models.py", line 75, in create_link
blob_key = files.blobstore.get_blob_key(blobstore_file)
File "/home/radek/google_appengine/google/appengine/api/files/blobstore.py", line 126, in get_blob_key
namespace='')])[0]
File "/home/radek/google_appengine/google/appengine/api/datastore.py", line 651, in Get
return GetAsync(keys, **kwargs).get_result()
File "/home/radek/google_appengine/google/appengine/api/datastore.py", line 626, in GetAsync
return _GetConnection().async_get(config, keys, local_extra_hook)
File "/home/radek/google_appengine/google/appengine/datastore/datastore_rpc.py", line 1565, in async_get
pbs = [key_to_pb(key) for key in keys]
File "/home/radek/google_appengine/google/appengine/ext/ndb/model.py", line 629, in key_to_pb
return key.reference()
But unfortunately this might be a genuine bug outlined here. I get this error only when I run this inside a transaction. Otherwise, everything works ok and I am able to retrieve the image from the url just fine.