Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6628385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:07:30+00:00 2026-05-25T22:07:30+00:00

I read the tutorial and all the sources I could find about displaying an

  • 0

I read the tutorial and all the sources I could find about displaying an image saved in datastore and still I could not make it work. I appreciate any help. This is my previous question.

The code below, for /displayimage shows broken link for the image; and for /image it gives BadKeyError: Invalid string key . According to Nick Johnson reply here I must be passing an empty string for img_id but logging.info in /display image shows this key: (((result.key():)))) agpkZXZ-dGluZy0xcg8LEghIb21lUGFnZRjOCAw. Thanks for your help.

class HomePage(db.Model):
    thumbnail = db.BlobProperty()
    firm_name = db.StringProperty()

class ImageUpload(webapp.RequestHandler):
    def get(self):
...        
        self.response.out.write("""
        <form action="/imagesave" enctype="multipart/form-data" method="post">
        <div><label>firm name:</label> <input type="text" name="firm_name" size=40></div>
        <div><input type="file" name="img" /></div>
        <div><input type="submit" value="Upload image"></div>
        </form>
        """)

class ImageSave(webapp.RequestHandler):
    def post(self):
        homepage = HomePage()
        thumbnail = self.request.get("img")
        firm_name = self.request.get("firm_name")
        homepage.thumbnail = db.Blob(thumbnail)
        homepage.firm_name = firm_name
        homepage.put()

        self.redirect("/imageupload")

class ImageResize(webapp.RequestHandler):
    def post(self):
        q = HomepageImage.all()
        q.filter("firm_name", "mta")
        qTable = q.get()

        if qTable:
            qTable.thumbnail = db.Blob(images.resize(self.request.get("img"), 32, 32))
            db.put(qTable)
        else:
            self.response.out.write("""firm not found""")
        self.redirect("/imageupload")

class DisplayImage(webapp.RequestHandler):
    def get(self):
...
        query = HomePage.all()
        query.filter("firm_name", "mta")
        result = query.get()

        self.response.out.write("""firm name: %s""" % result.firm_name)

        #self.response.out.write("""<img src="img?img_id=%s"></img>""" %
        #chenged this line as systempuntoout's comment to:
        self.response.out.write("""<img src="/image?img_id=%s"></img>""" %
        result.key())
        #but I still get the same error
class Image(webapp.RequestHandler):
    def get(self):
...
    #I am adding the next line to show that "img_id" is an empty string.
    #why "img_id" empty here?

    img_id = self.request.get("img_id")
    logging.info("""**************************img_id: %s**************************""" % img_id)
    #**************************img_id: **************************

        homepage = db.get(self.request.get("img_id"))

        if homepage.thumbnail:
            self.response.headers['Content-Type'] = "image/jpg"
            self.response.out.write(homepage.thumbnail)
        else:
            self.response.out.write("no image")


application = webapp.WSGIApplication(
[
("/imageresize",ImageResize),
("/imageupload", ImageUpload),
("/displayimage", DisplayImage),
("/imagesave", ImageSave),
("/image", Image),
],                                      
debug=True
)

def main():
    run_wsgi_app(application)
if __name__ == "__main__":
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:07:31+00:00Added an answer on May 25, 2026 at 10:07 pm

    You are pointing the image source to a not defined wrong img route .
    The correct link should point to /image like this:

    <img src="/image?img_id=%s"></img>
    

    I’ve tested your code with my correction and it works nicely:

    from google.appengine.ext import db
    from google.appengine.api import users
    from google.appengine.ext import webapp
    from google.appengine.ext.webapp.util import run_wsgi_app
    import logging
    
    
    class HomePage(db.Model):
        thumbnail = db.BlobProperty()
        firm_name = db.StringProperty()
    
    class ImageUpload(webapp.RequestHandler):
        def get(self):
            self.response.out.write("""
            <form action="/imagesave" enctype="multipart/form-data" method="post">
            <div><label>firm name:</label> <input type="text" name="firm_name" size=40></div>
            <div><input type="file" name="img" /></div>
            <div><input type="submit" value="Upload image"></div>
            </form>
            """)
    
    class ImageSave(webapp.RequestHandler):
        def post(self):
            homepage = HomePage()
            thumbnail = self.request.get("img")
            firm_name = self.request.get("firm_name")
            homepage.thumbnail = db.Blob(thumbnail)
            homepage.firm_name = firm_name
            homepage.put()
            self.redirect("/imageupload")
    
    class ImageResize(webapp.RequestHandler):
        def post(self):
            q = HomepageImage.all()
            q.filter("firm_name", "mta")
            qTable = q.get()
            if qTable:
                qTable.thumbnail = db.Blob(images.resize(self.request.get("img"), 32, 32))
                db.put(qTable)
            else:
                self.response.out.write("""firm not found""")
            self.redirect("/imageupload")
    
    class DisplayImage(webapp.RequestHandler):
        def get(self):
            query = HomePage.all()
            query.filter("firm_name", "mta")
            result = query.get()
            self.response.out.write("""firm name: %s""" % result.firm_name)
            self.response.out.write("""<img src="/image?img_id=%s"></img>""" %
            result.key())
    
    class Image(webapp.RequestHandler):
        def get(self):
            img_id = self.request.get("img_id")
            logging.info("""**************************img_id: %s**************************""" % img_id)
            homepage = db.get(self.request.get("img_id"))
            if homepage.thumbnail:
                    self.response.headers['Content-Type'] = "image/jpg"
                    self.response.out.write(homepage.thumbnail)
            else:
                    self.response.out.write("no image")
    
    
    application = webapp.WSGIApplication(
    [
    ("/imageresize",ImageResize),
    ("/imageupload", ImageUpload),
    ("/displayimage", DisplayImage),
    ("/imagesave", ImageSave),
    ("/image", Image),
    ],                                      
    debug=True
    )
    
    def main():
        run_wsgi_app(application)
    if __name__ == "__main__":
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently read a jQuery tutorial about best practices. I usually run all my
I once read a tutorial about how to create a new form and make
I have read all questions about Fluent nHibernate and didnt find answer for that.
I've read the manual and saw some tutorial, but still, I do not understand
Is there any book or links that I can read some tutorial about the
Where can I find a Qt tutorial in PDF format. I have looked all
I have read several tutorial concerning the for hibernate. I'm still getting confusion. Does
I've read the Python informal tutorial on slicing, which all makes sense to me
I read this tutorial http://tipsandtricks.runicsoft.com/Cpp/BitmapTutorial.html about bitmap and it really helped..I need to read
I just learning yii framework and read this tutorial about yii how to setup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.