Displaying image from Blob

33 views
Skip to first unread message

Toney

unread,
Nov 10, 2008, 2:53:54 PM11/10/08
to Google App Engine
I’m trying to display an image from the data store using the hello
world sample. When I run the code below I get a blank image displayed
in FireFox. I'm sure the image is uploaded because when I initially
tried {{ greeting.pic1|escape }} in the html file I got a bunch of
garbage back.

Can someone pls let me know what i'm doing wrong.

class Greeting(db.Model):
author = db.UserProperty()
date = db.DateTimeProperty(auto_now_add=True)
pic1 = db.BlobProperty()


class GetImage(webapp.RequestHandler):

def get(self):

query_str = "SELECT * FROM Greeting ORDER BY date DESC LIMIT
10" result[0]
self.response.headers['Content-Type'] = 'image/jpg'
self.response.out.write(result.picture)

application = webapp.WSGIApplication(
[('/upload/', MainPage),
('/upload/sign', Guestbook),
('/pic', GetImage)],
debug=True)


----------HTML-----------
{% for greeting in greetings %}

<img src="/pic?author={{greeting. author}}"></img>

{% endfor %}



Marcelo

unread,
Nov 10, 2008, 3:15:34 PM11/10/08
to Google App Engine
I think is the content-type it should be image/jpeg

Toney

unread,
Nov 10, 2008, 3:28:53 PM11/10/08
to Google App Engine
changed it, still no luck

Alexander Kojevnikov

unread,
Nov 10, 2008, 5:07:21 PM11/10/08
to Google App Engine
You write 'result.picture' but your property is called 'pic1'. Try
this code:

def get(self):
query_str = "SELECT * FROM Greeting ORDER BY date DESC"
result = GqlQuery(query_str).get()
self.response.headers['Content-Type'] = 'image/jpeg'
self.response.out.write(result.pic1)

Toney

unread,
Nov 10, 2008, 8:36:35 PM11/10/08
to Google App Engine
Thanks Alexander, I had to make some other changes but your code
helped mostly.

On Nov 10, 5:07 pm, Alexander Kojevnikov <alexan...@kojevnikov.com>
wrote:
Reply all
Reply to author
Forward
0 new messages