goggin13
goggin13

Reputation: 7976

Google App Engine Python: get image upload size server-side

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?

Upvotes: 1

Views: 972

Answers (2)

bboe
bboe

Reputation: 4402

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

Upvotes: 5

Auston
Auston

Reputation: 478

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

try:    
    images.Transform()
except Transform.RequestTooLargeError:
    inform
else:
    proceed

Upvotes: 1

Related Questions