Reading from the blobstore

34 views
Skip to first unread message

Rik Scarborough

unread,
Apr 9, 2012, 10:52:21 AM4/9/12
to gae...@googlegroups.com
I see that you have to have the BlobKey to read a file from the blobstore.  How do you get that key from an already existing blob?

Or is there a better way to store a JSON or XML file that is transmitted to new users?

~Rik

Robert Fischer

unread,
Apr 9, 2012, 11:15:08 AM4/9/12
to gae...@googlegroups.com
Although the easier way to save the XML/JSON is to have the results
cached for you at the routes level:

https://gaelyk.appspot.com/tutorial/url-routing#caching

~~ Robert.
Science tells us we are merely beasts, but we don't feel like that. We
feel like angels trapped inside the bodies of beasts, forever craving
transcendence.
(VS Ramachandran, cognitive neuroscientist)

On Mon, Apr 9, 2012 at 11:12 AM, Robert Fischer <smokej...@gmail.com> wrote:
> Either you have the user give you the blobstore key (via the URL), or
> you have them give you a key which you look up in the DataStore (you
> can store Blobstore Keys as properties in the data store).
>
> ~~ Robert.
> Science tells us we are merely beasts, but we don't feel like that. We
> feel like angels trapped inside the bodies of beasts, forever craving
> transcendence.
> (VS Ramachandran, cognitive neuroscientist)

>> --
>> You've received this message because you've subscribed to the Gaelyk Google
>> Group.
>> To send an email to the group, please write to: gae...@googlegroups.com
>> To unsuscribe from this group: gaelyk+un...@googlegroups.com
>> To show more options: http://groups.google.fr/group/gaelyk?hl=en

Robert Fischer

unread,
Apr 9, 2012, 11:12:55 AM4/9/12
to gae...@googlegroups.com
Either you have the user give you the blobstore key (via the URL), or
you have them give you a key which you look up in the DataStore (you
can store Blobstore Keys as properties in the data store).

~~ Robert.
Science tells us we are merely beasts, but we don't feel like that. We
feel like angels trapped inside the bodies of beasts, forever craving
transcendence.
(VS Ramachandran, cognitive neuroscientist)

On Mon, Apr 9, 2012 at 10:52 AM, Rik Scarborough <rik...@gmail.com> wrote:

Rik Scarborough

unread,
Apr 9, 2012, 12:17:47 PM4/9/12
to gae...@googlegroups.com
So, when I save the blob to the blobstore, I have to save the key off to the datastore?

~Rik

Rik Scarborough

unread,
Apr 9, 2012, 12:19:45 PM4/9/12
to gae...@googlegroups.com
I'm already caching the data. The cache is then lost when the instance is shut down and I have to scan the entire table to reload the cache. If I can save a snapshot of the data, I only have to query the database for updates.

~Rik

Robert Fischer

unread,
Apr 9, 2012, 2:47:22 PM4/9/12
to gae...@googlegroups.com
When you save the blob to the blobstore, you have to provide some way
to look up the blob later on. This means deriving the key from a
user's later request. This usually involves storing the key to the
data store or giving it to the user. You can also give it to the user
and have the user give it back to you somehow — although in that case,
I'd also suggest a queue entry with the blob key to clean up the
blobstore when the blob expires.

~~ Robert.
Science tells us we are merely beasts, but we don't feel like that. We
feel like angels trapped inside the bodies of beasts, forever craving
transcendence.
(VS Ramachandran, cognitive neuroscientist)

Guillaume Laforge

unread,
Apr 9, 2012, 3:29:10 PM4/9/12
to gae...@googlegroups.com
For information...

JavaDoc of the BlobKey class:
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/blobstore/BlobKey

One can get a string representation of the BlobKey calling blobKey.keyString (ie. getKeyString()).
You can store that string representation somewhere (datastore, memcache, url parameter, etc).
And then, you can call new BlobKey(stringRepresentation) to get the key.

Guillaume
Guillaume Laforge
Groovy Project Manager
SpringSource, a division of VMware


Rik Scarborough

unread,
Apr 9, 2012, 3:31:16 PM4/9/12
to gae...@googlegroups.com
Ah, I think that last part may have been something I was doing wrong. I will try that tonight.

~Rik
Reply all
Reply to author
Forward
0 new messages