How do I use get_serving_url correctly?

402 views
Skip to first unread message

Flips

unread,
Aug 24, 2010, 4:53:24 PM8/24/10
to Google App Engine
Hi,

how do I use get_serving_url correctly if I'd like to host a gallery
of 28 pictures? I currently fetch all blob_keys and call 28 times the
get_serving_url method to get my image urls. But this attempt is
really slow (about 12 seconds). Would it be smarter to call
get_serving_url if the blob has been created and store the image url
in datastore?

Best Regards
Philip

Ikai L (Google)

unread,
Aug 26, 2010, 8:56:53 PM8/26/10
to google-a...@googlegroups.com
Yes, you can cache the result. In practice, subsequent calls of get_serving_url on the same blob should be faster, but if you have more new blobs than old ones on a page it can be slow. The resulting URL only becomes invalid if the blob is deleted.


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.




--
Ikai Lan 
Developer Programs Engineer, Google App Engine

Nickolas Daskalou

unread,
Aug 27, 2010, 3:36:13 AM8/27/10
to google-a...@googlegroups.com
Ikai, is there any way of doing this asynchronously (like URLFetch fetch() calls)?

Eg: (copied mostly from http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html)

from google.appengine.api import images

# ...

blob_keys = [..., ..., ......]
blob_key_serving_urls = []
size = ...
crop = ...

def handle_result(rpc):
  url = rpc.get_result()
  blob_key_serving_urls.append(url)

# Use a helper function to define the scope of the callback.
def create_callback(rpc):
  return lambda: handle_result(rpc)

rpcs = []
for blob_key in blob_keys:
  images.create_rpc()
  rpc.callback = create_callback(rpc)
  images.make_get_serving_url_call(rpc, blob_key, size, crop)
  rpcs.append(rpc)

# ...

for rpc in rpcs:
  rpc.wait()

# blob_key_serving_urls should now contain the serving URLs.

Or should we add this as a feature request?

Nick

Matt H

unread,
Aug 28, 2010, 4:19:12 PM8/28/10
to Google App Engine
I don't think so. AFAIK the URL is intended to be persisted - not
regenerated repeatedly.

On Aug 27, 8:36 am, Nickolas Daskalou <n...@daskalou.com> wrote:
> Ikai, is there any way of doing this asynchronously (like URLFetch fetch()
> calls)?
>
> Eg: (copied mostly fromhttp://code.google.com/appengine/docs/python/urlfetch/asynchronousreq...
> )
> >> google-appengi...@googlegroups.com<google-appengine%2Bunsubscrib e...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/google-appengine?hl=en.
>
> > --
> > Ikai Lan
> > Developer Programs Engineer, Google App Engine
> > Blog:http://googleappengine.blogspot.com
> > Twitter:http://twitter.com/app_engine
> > Reddit:http://www.reddit.com/r/appengine
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Google App Engine" group.
> > To post to this group, send email to google-a...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-appengi...@googlegroups.com<google-appengine%2Bunsubscrib e...@googlegroups.com>
> > .

Nickolas Daskalou

unread,
Aug 29, 2010, 12:18:00 AM8/29/10
to google-a...@googlegroups.com
Matt, even if that's the case, it'd be nice if the delay of dozens of get_serving_url() API calls could be parallelised and not added up sequentially (which is what I was trying to find out in my long-winded question to Ikai).

Nick


To unsubscribe from this group, send email to google-appengi...@googlegroups.com.

Geoffrey Spear

unread,
Aug 29, 2010, 8:24:51 AM8/29/10
to Google App Engine


On Aug 29, 12:18 am, Nickolas Daskalou <n...@daskalou.com> wrote:
> Matt, even if that's the case, it'd be nice if the delay of dozens of
> get_serving_url() API calls could be parallelised and not added up
> sequentially (which is what I was trying to find out in my long-winded
> question to Ikai).

I don't believe it can be, at least at the moment. If you know the
parameters you're going to use it seems like generating the serving
URL in your blobstore upload callback and storing it once at the time
of the upload (or shortly after the upload with a deferred task) would
be the way to go.
Reply all
Reply to author
Forward
0 new messages