views:

42

answers:

3
+1  Q: 

images API / Error

I'm working on a project and I used the the Images Python API . For instance in the example given in http://code.google.com/appengine/docs/python/images/usingimages.html I get an error when ever I do not upload a photo, How can I modify the code so I don't get an error when I don't post anything.

thanks

+2  A: 

Try changing the line

avatar = images.resize(self.request.get("img"), 32, 32)

to check if self.request.get("img") is empty:

posted_avatar = self.request.get("img")
if posted_avatar:
  avatar = images.resize(posted_avatar, 32, 32)
  greeting.avatar = db.Blob(avatar)

greeting.put()
Constantin
+1; beat me to it :-)
Adam Bernier
@Adam Bernier, your sample got me thinking whether `put()` should be moved out of `if`...
Constantin
+1  A: 

You can simply check if that input element of the form was populated.

From the example code:

<div><input type="file" name="img" /></div>

You'd then add a conditional (if statement) to your handler:

if self.request.get("img"):
    # do image processing stuff here

Here's a simple bit of code that does what you want: http://bitbucket.org/abernier/pocasi/src/tip/handlers/admin.py#cl-102
Template code here: http://bitbucket.org/abernier/pocasi/src/tip/templates/create.html

Adam Bernier
A: 

thank you so much guys

zozo
Would be nice to mark the answer you liked most as "Accepted".
Constantin