开发者

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
开发者_StackOverflow中文版else:
    proceed

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


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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜