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

  • SEARCH
  • Home
  • 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 8304749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:55:41+00:00 2026-06-08T17:55:41+00:00

I have a function that gets an image from a form, and put’s it

  • 0

I have a function that gets an image from a form, and put’s it into the database along with the username. So, here is my database:

class Imagedb(db.Model):
    name = db.StringProperty(required = True)
    image = db.BlobProperty()

And here is the code that writes to the database:

class Change_Profile_Image(MainHandler):
    def get(self):
        if self.user:
            self.render('change_profile_image.html', username = self.user.name, firstname=self.user.first_name)
        else:
            self.render('change_profile_image.html')

    def post(self):
        imagedb = Imagedb(name = self.user.name)
        imageupl = self.request.get("img")
        imagedb.image = db.Blob(imageupl)
        imagedb.put()
        self.redirect('/profile')

Any who, it works awesome. Except for one thing. What i’m trying to accomplish is only storing ONE profile picture. What ends up happening is this:

Say I am the user admin. Ill upload a display pic, that pic shows in the profile. Ill upload another one, that one shows. Cool, except for the fact that I have 2 objects in my database that have the name = admin attribute. I would like to edit this…

    def post(self):
        imagedb = Imagedb(name = self.user.name)
        imageupl = self.request.get("img")
        imagedb.image = db.Blob(imageupl)
        imagedb.put()
        self.redirect('/profile')

so that I can post images to the database, but if one exists, it is overwritten. Could anyone help me with this please? I’m relatively new to python and app engine.

If something is unclear, please let me know.

  • 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-06-08T17:55:42+00:00Added an answer on June 8, 2026 at 5:55 pm

    You want to set the key of the Imagedb entity to “name”. Essentially, you don’t need the name field, but you’ll instantiate it like

    imagedb = Imagedb(key_name = self.user.name)
    

    The key is a required field on all entities. By using your user name as the key it means every time you refere to a given key, it’s the same entity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Java code I have function that gets file from the client in
Here's a brief rundown of my issue: I have a JavaScript function that gets
I have this function in jQuery that gets data from a page with POST,
I have a form that takes some input from a user and then gets
I have a function that sending a code gets a description through various formatings,
I have a UIViewController and in that controller, i am fetching an image from
I have a gridview that displays data from a database. The datbase stores the
I have a form that appears as shown in the attached image. I have
I have an Image object that gets resized to the containers size when the
I have a function that gets the contents of a table row and displays

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.