views:

51

answers:

2

Hi,

I am making a P2P Media sharing feature where users can share Files (images, mp3 etc) with others. When a User shares a file with the other I simply send them the link to that file. The links looks like:

http://www.domain.com/file?q=unique_key

Now, the unique_key must be alpha-numeric and not easily guessable, so i plan to use the file record's encoded key.

This was easy in my earlier Python GAE App, But in my new Java App, I am unable to get hold of this Key value, all i get is an ID which is Long (numeric).

My Entity has a field called ID which is Long, but in my GAE Admin console there is a entity encoded key which is alpha numeric, and I hope thats unique for every record in my database. So how to access that?

I am using Objectify and when i create a new key like this

Key myKey = new Key (FileEntity.class, entityID);

myKey is a string with some text in it, but its the uniqye alpha numeric id that I am looking for.

Sorry for my fuzzy question, please help.

+3  A: 

Since you are using objectify, you can get the string encoded key by using the method

ObjectifyService.factory().keyToString( myKey );
Ashwin Prabhu
Thanks Ashwin, your code worked for me perfectly in my context.
charming30
+3  A: 

Encoded string keys are easily guessible - they're encoded protocol buffers containing the app ID, kind name, and ID. If you need values that aren't easily guessable, I would recommend generating UUIDs, and using those as key names (string keys), instead.

Nick Johnson
Thanks, this input surely helped.
charming30