views:

130

answers:

2

I am building a Google App Engine App that lets users upload images; I have everything working fine, but I am struggling to find a way to ensure that the user does not upload an image too large (because I am resizing the images, so this crashes my python script). When a user uploads a large image, I get this error

RequestTooLargeError: The request to API call images.Transform() was too large.

I know that there is a size limitation on what GAE allows for it's image API, I am just trying to find a way to deal with this server side; something along the lines of

if (image is too large):
    inform user
else:
    proceed

I haven't had any luck finding the right python code to do this; can anyone help me out?

+1  A: 

I am not sure I understand your problem completely but maybe a try would work?

try:    
    images.Transform()
except Transform.RequestTooLargeError:
    inform
else:
    proceed
Auston
Yup, thats what I was looking for, I was just missing the appropriate way to reference the RequestTooLargeError (see above answer from bboe). Thanks for your help!
goggin13
+4  A: 
from google.appengine.runtime import apiproxy_errors

...

try:
    #the code you are getting the error at
except apiproxy_errors.RequestTooLargeError, message:
    print message # or something else
bboe
Perfect, that's just what I was looking for. I tried all sorts of those Try-Excepts, but I was missing that import statement, so I couldn't even compile while referencing the RequestTooLargeEror.Thank you so much!
goggin13
I'm pretty sure I had to search through the appengine source code to find where this error was declared after I first encountered it. Glad it worked for you :)
bboe