On Sunday, February 26, 2012 12:19:17 AM UTC-5, Peter G. wrote: > > How would one obtain the URL to a image blob stored on GAE's > datastore? A lot of the threads I've looked at were all for generating > an download output for views, but I need this for the Controller since > I'm returning this as a JSON element. > > For example, the auth_user table has a field 'avatar' and another blob > field 'avatar_blob'. Ideally I can simply return a JSON like: > { "avatar": "http://<domain>/<app>/avatars/username_avatar.gif" } > > Where username_avatar.gif would map to the stored blob image for that > user's avatar.
Assuming you use web2py's standard "upload" field type to upload the images, then you would still use the standard download process as well. See the "Uploading files in database" section in http://web2py.com/books/default/chapter/29/13 for details on setting up database storage of uploads. And for downloading, see the response.downloaddescription here: http://web2py.com/books/default/chapter/29/4#response. In your case, it would be something like: db.define_table('auth_user', ..., Field('avatar', 'upload', uploadfield='avatar_blob'), Field('avatar_blob', 'blob'), ...) def download(): return response.download(request, db) URL for a particular user's avatar: URL('default', 'download', args=auth.user.avatar) Anthony